public static void Serialize(Stream stream, object value) { BinaryWriter writer = new BinaryWriter(stream); FieldInfo[] fields = value.GetType().GetFields(); foreach (FieldInfo f in fields) { Type t = f.FieldType; object v = f.GetValue(value); switch (t.FullName) { case "System.Boolean": writer.Write((bool)v); break; case "System.Char": writer.Write((char)v); break; case "System.Byte": writer.Write((byte)v); break; case "System.SByte": writer.Write((sbyte)v); break; case "System.Int16": writer.Write((short)v); break; case "System.UInt16": writer.Write((ushort)v); break; case "System.Int32": writer.Write((int)v); break; case "System.UInt32": writer.Write((uint)v); break; case "System.Int64": writer.Write((long)v); break; case "System.UInt64": writer.Write((ulong)v); break; case "System.Single": writer.Write((float)v); break; case "System.Double": writer.Write((double)v); break; case "System.Decimal": writer.Write((decimal)v); break; case "System.String": writer.Write((string)v); break; default: XCSharp.Serialize(stream, v); break; } } }