Пример #1
0
 public void Save(Stream stream)
 {
     using (var writer = new MyBinaryWriter(stream, Data.GetSize()))
     {
         Data.Write(writer);
         Console.WriteLine(writer.DataStartOffset);
     }
 }
Пример #2
0
        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);
        }
Пример #3
0
 public override void Write(MyBinaryWriter stream)
 {
     throw new NotImplementedException();
 }