PgmTransport.PgmSocket.ConvertStructToBytes C# (CSharp) Method

ConvertStructToBytes() public static method

public static ConvertStructToBytes ( object obj ) : byte[]
obj object
return byte[]
        public static byte[] ConvertStructToBytes(object obj)
        {
            int structSize = Marshal.SizeOf(obj);
            byte[] allData = new byte[structSize];
            GCHandle handle = GCHandle.Alloc(allData, GCHandleType.Pinned);
            Marshal.StructureToPtr(obj, handle.AddrOfPinnedObject(), false);
            handle.Free();
            return allData;
        }