public void Save(Stream stream) { using (var writer = new MyBinaryWriter(stream, Data.GetSize())) { Data.Write(writer); Console.WriteLine(writer.DataStartOffset); } }
public static void Write <T>(this MyBinaryWriter writer, T value) where T : new() { if (typeof(T).IsSubclassOf(typeof(Element))) { ((object)value as Element).Write(writer); return; } var size = Marshal.SizeOf(typeof(T)); var bytes = new byte[size]; var ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(value, ptr, true); Marshal.Copy(ptr, bytes, 0, size); Marshal.FreeHGlobal(ptr); writer.Write(bytes); }
public override void Write(MyBinaryWriter stream) { throw new NotImplementedException(); }