/// <summary> /// Default constructor for creating InteropRecipientCollection. /// </summary> /// <param name="outer"></param> public InteropRecipientCollection(RecipientCollection outer) { _count = outer.Count; if (_count == 0) { _handle = IntPtr.Zero; return; } // allocate enough memory to hold all recipients int size = Marshal.SizeOf(typeof(MapiMailMessage.MapiHelperInterop.MapiRecipDesc)); _handle = Marshal.AllocHGlobal(_count * size); // place all interop recipients into the memory just allocated var ptr = _handle; foreach (Recipient native in outer) { MapiMailMessage.MapiHelperInterop.MapiRecipDesc interop = native.GetInteropRepresentation(); // stick it in the memory block Marshal.StructureToPtr(interop, ptr, false); ptr += size; } }
/// <summary> /// Returns an interop representation of a recepient. /// </summary> /// <returns></returns> internal MapiMailMessage.MapiHelperInterop.MapiRecipDesc GetInteropRepresentation() { var interop = new MapiMailMessage.MapiHelperInterop.MapiRecipDesc(); if (DisplayName == null) { interop.Name = Address; } else { interop.Name = DisplayName; interop.Address = Address; } interop.RecipientClass = (int)RecipientType; return(interop); }