4 // Lluis Sanchez Gual (lluis@ideary.com)
6 // (C) 2003 Lluis Sanchez Gual
10 namespace System.Runtime.Serialization.Formatters.Binary
\r
12 internal class BinaryCommon
\r
14 // Header present in all binary serializations
\r
15 public static byte[] BinaryHeader = new Byte[] {0,1,0,0,0,255,255,255,255,1,0,0,0,0,0,0,0};
\r
17 static Type[] _typeCodesToType;
\r
18 static byte[] _typeCodeMap;
\r
20 static BinaryCommon()
\r
22 _typeCodesToType = new Type [19];
\r
23 _typeCodesToType[(int)BinaryTypeCode.Boolean] = typeof (Boolean);
\r
24 _typeCodesToType[(int)BinaryTypeCode.Byte] = typeof (Byte);
\r
25 _typeCodesToType[(int)BinaryTypeCode.Char] = typeof (Char);
\r
26 _typeCodesToType[(int)BinaryTypeCode.DateTime] = typeof (DateTime);
\r
27 _typeCodesToType[(int)BinaryTypeCode.Decimal] = typeof (Decimal);
\r
28 _typeCodesToType[(int)BinaryTypeCode.Double] = typeof (Double);
\r
29 _typeCodesToType[(int)BinaryTypeCode.Int16] = typeof (Int16);
\r
30 _typeCodesToType[(int)BinaryTypeCode.Int32] = typeof (Int32);
\r
31 _typeCodesToType[(int)BinaryTypeCode.Int64] = typeof (Int64);
\r
32 _typeCodesToType[(int)BinaryTypeCode.SByte] = typeof (SByte);
\r
33 _typeCodesToType[(int)BinaryTypeCode.Single] = typeof (Single);
\r
34 _typeCodesToType[(int)BinaryTypeCode.UInt16] = typeof (UInt16);
\r
35 _typeCodesToType[(int)BinaryTypeCode.UInt32] = typeof (UInt32);
\r
36 _typeCodesToType[(int)BinaryTypeCode.UInt64] = typeof (UInt64);
\r
37 _typeCodesToType[(int)BinaryTypeCode.Null] = null;
\r
38 _typeCodesToType[(int)BinaryTypeCode.String] = typeof (string);
\r
40 _typeCodeMap = new byte[30];
\r
41 _typeCodeMap[(int)TypeCode.Boolean] = (byte) BinaryTypeCode.Boolean;
\r
42 _typeCodeMap[(int)TypeCode.Byte] = (byte) BinaryTypeCode.Byte;
\r
43 _typeCodeMap[(int)TypeCode.Char] = (byte) BinaryTypeCode.Char;
\r
44 _typeCodeMap[(int)TypeCode.DateTime] = (byte) BinaryTypeCode.DateTime;
\r
45 _typeCodeMap[(int)TypeCode.Decimal] = (byte) BinaryTypeCode.Decimal;
\r
46 _typeCodeMap[(int)TypeCode.Double] = (byte) BinaryTypeCode.Double;
\r
47 _typeCodeMap[(int)TypeCode.Int16] = (byte) BinaryTypeCode.Int16;
\r
48 _typeCodeMap[(int)TypeCode.Int32] = (byte) BinaryTypeCode.Int32;
\r
49 _typeCodeMap[(int)TypeCode.Int64] = (byte) BinaryTypeCode.Int64;
\r
50 _typeCodeMap[(int)TypeCode.SByte] = (byte) BinaryTypeCode.SByte;
\r
51 _typeCodeMap[(int)TypeCode.Single] = (byte) BinaryTypeCode.Single;
\r
52 _typeCodeMap[(int)TypeCode.UInt16] = (byte) BinaryTypeCode.UInt16;
\r
53 _typeCodeMap[(int)TypeCode.UInt32] = (byte) BinaryTypeCode.UInt32;
\r
54 _typeCodeMap[(int)TypeCode.UInt64] = (byte) BinaryTypeCode.UInt64;
\r
55 _typeCodeMap[(int)TypeCode.String] = (byte) BinaryTypeCode.String;
\r
58 public static bool IsPrimitive (Type type)
\r
60 return type.IsPrimitive || type == typeof (DateTime) || type == typeof (Decimal);
\r
63 public static byte GetTypeCode (Type type)
\r
65 return _typeCodeMap [(int)Type.GetTypeCode(type)];
\r
68 public static Type GetTypeFromCode (int code)
\r
70 return _typeCodesToType [code];
\r
74 internal enum BinaryElement : byte
\r
84 BoxedPrimitiveTypeValue = 8,
91 ArrayOfPrimitiveType = 15,
101 internal enum TypeTag : byte
110 ArrayOfPrimitiveType = 7
113 internal enum ArrayStructure : byte
115 SingleDimensional = 0,
120 internal enum MethodFlags : byte
123 PrimitiveArguments = 2,
124 ArgumentsInSimpleArray = 4,
125 ArgumentsInMultiArray = 8,
126 ExcludeLogicalCallContext = 16,
127 IncludesLogicalCallContext = 64,
128 IncludesSignature = 128,
131 NeedsInfoArrayMask = 4 + 8 + 64 + 128
134 internal enum ReturnTypeTag : byte
\r
142 enum BinaryTypeCode : byte
\r