packages/Windows API Code Pack 1.1/source/Samples/DirectX/CS/UtilitiesLibrary/MeshLoader/XMeshLoader.cs
/// <summary>
/// Copies an arbitrary structure into a byte array
/// </summary>
/// <param name="anything"></param>
/// <returns></returns>
Copies an arbitrary structure into a byte array
Copies an arbitrary structure into a byte array
public byte[] RawSerialize(object anything)
        {
            int rawsize = Marshal.SizeOf(anything);
            IntPtr buffer = Marshal.AllocHGlobal(rawsize);
            try
            {
                Marshal.StructureToPtr(anything, buffer, false);
                byte[] rawdatas = new byte[rawsize];
                Marshal.Copy(buffer, rawdatas, 0, rawsize);
                return rawdatas;
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
public byte [ ] RawSerialize ( object anything ) { int rawsize = Marshal . SizeOf ( anything ) ; IntPtr buffer = Marshal . AllocHGlobal ( rawsize ) ; try { Marshal . StructureToPtr ( anything , buffer , false ) ; byte [ ] rawdatas = new byte [ rawsize ] ; Marshal . Copy ( buffer , rawdatas , 0 , rawsize ) ; return rawdatas ; } finally { Marshal . FreeHGlobal ( buffer ) ; } }
Copies an arbitrary structure into a byte array
Copies an arbitrary structure into a byte array
None
anything
object
None