/// <summary> /// The GetStructureIntPtr. /// </summary> /// <param name="structure">The structure<see cref="object"/>.</param> /// <returns>The <see cref="IntPtr"/>.</returns> public unsafe static IntPtr GetStructureIntPtr(object structure) { int size = 0; if (structure is ValueType) { Type t = structure.GetType(); if (t.IsPrimitive || t.IsLayoutSequential) { return(new IntPtr(extractor.ValueStructureToPointer(structure))); } if (structure is DateTime) { size = 8; structure = ((DateTime)structure).ToBinary(); } //else if (structure is ISerialNumber) // size = 24; //else if (structure is IUnique) // size = 8; else if (structure is Enum) { size = 4; structure = Convert.ToInt32((Enum)structure); } else { size = Marshal.SizeOf(structure); } } else { size = Marshal.SizeOf(structure); } IntPtr p = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(structure, p, true); return(p); }
/// <summary> /// The ValueStructureToIntPtr. /// </summary> /// <param name="structure">The structure<see cref="object"/>.</param> /// <returns>The <see cref="IntPtr"/>.</returns> public static unsafe IntPtr ValueStructureToIntPtr(object structure) { return(new IntPtr(_extract.ValueStructureToPointer(structure))); }