示例#1
0
文件: M2.cs 项目: Dramacydal/M2Lib
 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();
 }