public unsafe T ReadStruct <T>() where T : struct { var s = ILHacks.SizeOf <T>(); fixed(byte *ptr = ReadBytes(s)) { var r = default(T); ILHacks.Cpblk((void *)ptr, ref r); return(r); } }
public unsafe void Write <T>(T value) where T : struct { var s = ILHacks.SizeOf <T>(); var stuff = Marshal.AllocHGlobal(s); try { ILHacks.Cpblk(ref value, (void *)stuff); Write(stuff, s); } finally { Marshal.FreeHGlobal(stuff); } }