static AMFWriter() { Dictionary <Type, IAMFWriter> dictionary = new Dictionary <Type, IAMFWriter>(); AMF0NumberWriter writer = new AMF0NumberWriter(); dictionary.Add(typeof(sbyte), writer); dictionary.Add(typeof(byte), writer); dictionary.Add(typeof(short), writer); dictionary.Add(typeof(ushort), writer); dictionary.Add(typeof(int), writer); dictionary.Add(typeof(uint), writer); dictionary.Add(typeof(long), writer); dictionary.Add(typeof(ulong), writer); dictionary.Add(typeof(float), writer); dictionary.Add(typeof(double), writer); dictionary.Add(typeof(decimal), writer); dictionary.Add(typeof(DBNull), new AMF0NullWriter()); AMF0SqlTypesWriter writer2 = new AMF0SqlTypesWriter(); dictionary.Add(typeof(INullable), writer2); dictionary.Add(typeof(SqlByte), writer2); dictionary.Add(typeof(SqlInt16), writer2); dictionary.Add(typeof(SqlInt32), writer2); dictionary.Add(typeof(SqlInt64), writer2); dictionary.Add(typeof(SqlSingle), writer2); dictionary.Add(typeof(SqlDouble), writer2); dictionary.Add(typeof(SqlDecimal), writer2); dictionary.Add(typeof(SqlMoney), writer2); dictionary.Add(typeof(SqlDateTime), writer2); dictionary.Add(typeof(SqlString), writer2); dictionary.Add(typeof(SqlGuid), writer2); dictionary.Add(typeof(SqlBinary), writer2); dictionary.Add(typeof(SqlBoolean), writer2); dictionary.Add(typeof(CacheableObject), new AMF0CacheableObjectWriter()); dictionary.Add(typeof(XmlDocument), new AMF0XmlDocumentWriter()); dictionary.Add(typeof(DataTable), new AMF0DataTableWriter()); dictionary.Add(typeof(DataSet), new AMF0DataSetWriter()); dictionary.Add(typeof(RawBinary), new RawBinaryWriter()); dictionary.Add(typeof(NameObjectCollectionBase), new AMF0NameObjectCollectionWriter()); dictionary.Add(typeof(XDocument), new AMF0XDocumentWriter()); dictionary.Add(typeof(XElement), new AMF0XElementWriter()); dictionary.Add(typeof(Guid), new AMF0GuidWriter()); dictionary.Add(typeof(string), new AMF0StringWriter()); dictionary.Add(typeof(bool), new AMF0BooleanWriter()); dictionary.Add(typeof(Enum), new AMF0EnumWriter()); dictionary.Add(typeof(char), new AMF0CharWriter()); dictionary.Add(typeof(DateTime), new AMF0DateTimeWriter()); dictionary.Add(typeof(Array), new AMF0ArrayWriter()); dictionary.Add(typeof(ASObject), new AMF0ASObjectWriter()); Dictionary <Type, IAMFWriter> dictionary2 = new Dictionary <Type, IAMFWriter>(); AMF3IntWriter writer3 = new AMF3IntWriter(); AMF3DoubleWriter writer4 = new AMF3DoubleWriter(); dictionary2.Add(typeof(sbyte), writer3); dictionary2.Add(typeof(byte), writer3); dictionary2.Add(typeof(short), writer3); dictionary2.Add(typeof(ushort), writer3); dictionary2.Add(typeof(int), writer3); dictionary2.Add(typeof(uint), writer3); dictionary2.Add(typeof(long), writer4); dictionary2.Add(typeof(ulong), writer4); dictionary2.Add(typeof(float), writer4); dictionary2.Add(typeof(double), writer4); dictionary2.Add(typeof(decimal), writer4); dictionary2.Add(typeof(DBNull), new AMF3DBNullWriter()); AMF3SqlTypesWriter writer5 = new AMF3SqlTypesWriter(); dictionary2.Add(typeof(INullable), writer5); dictionary2.Add(typeof(SqlByte), writer5); dictionary2.Add(typeof(SqlInt16), writer5); dictionary2.Add(typeof(SqlInt32), writer5); dictionary2.Add(typeof(SqlInt64), writer5); dictionary2.Add(typeof(SqlSingle), writer5); dictionary2.Add(typeof(SqlDouble), writer5); dictionary2.Add(typeof(SqlDecimal), writer5); dictionary2.Add(typeof(SqlMoney), writer5); dictionary2.Add(typeof(SqlDateTime), writer5); dictionary2.Add(typeof(SqlString), writer5); dictionary2.Add(typeof(SqlGuid), writer5); dictionary2.Add(typeof(SqlBinary), writer5); dictionary2.Add(typeof(SqlBoolean), writer5); dictionary2.Add(typeof(CacheableObject), new AMF3CacheableObjectWriter()); dictionary2.Add(typeof(XmlDocument), new AMF3XmlDocumentWriter()); dictionary2.Add(typeof(DataTable), new AMF3DataTableWriter()); dictionary2.Add(typeof(DataSet), new AMF3DataSetWriter()); dictionary2.Add(typeof(RawBinary), new RawBinaryWriter()); dictionary2.Add(typeof(NameObjectCollectionBase), new AMF3NameObjectCollectionWriter()); dictionary2.Add(typeof(XDocument), new AMF3XDocumentWriter()); dictionary2.Add(typeof(XElement), new AMF3XElementWriter()); dictionary2.Add(typeof(Guid), new AMF3GuidWriter()); dictionary2.Add(typeof(string), new AMF3StringWriter()); dictionary2.Add(typeof(bool), new AMF3BooleanWriter()); dictionary2.Add(typeof(Enum), new AMF3EnumWriter()); dictionary2.Add(typeof(char), new AMF3CharWriter()); dictionary2.Add(typeof(DateTime), new AMF3DateTimeWriter()); dictionary2.Add(typeof(Array), new AMF3ArrayWriter()); dictionary2.Add(typeof(ASObject), new AMF3ASObjectWriter()); dictionary2.Add(typeof(ByteArray), new AMF3ByteArrayWriter()); Dictionary <Type, IAMFWriter>[] dictionaryArray = new Dictionary <Type, IAMFWriter> [4]; dictionaryArray[0] = dictionary; dictionaryArray[3] = dictionary2; AmfWriterTable = dictionaryArray; classDefinitions = new Dictionary <string, ClassDefinition>(); }
static AMFWriter() { Dictionary <Type, IAMFWriter> amf0Writers = new Dictionary <Type, IAMFWriter>(); //AMF0 AMF0NumberWriter amf0NumberWriter = new AMF0NumberWriter(); /*0*/ amf0Writers.Add(typeof(SByte), amf0NumberWriter); amf0Writers.Add(typeof(Byte), amf0NumberWriter); amf0Writers.Add(typeof(Int16), amf0NumberWriter); amf0Writers.Add(typeof(UInt16), amf0NumberWriter); amf0Writers.Add(typeof(Int32), amf0NumberWriter); amf0Writers.Add(typeof(UInt32), amf0NumberWriter); amf0Writers.Add(typeof(Int64), amf0NumberWriter); amf0Writers.Add(typeof(UInt64), amf0NumberWriter); amf0Writers.Add(typeof(Single), amf0NumberWriter); amf0Writers.Add(typeof(Double), amf0NumberWriter); amf0Writers.Add(typeof(Decimal), amf0NumberWriter); amf0Writers.Add(typeof(bool), new AMF0BooleanWriter()); /*1*/ amf0Writers.Add(typeof(string), new AMF0StringWriter()); /*2*/ amf0Writers.Add(typeof(ASObject), new AMF0ASObjectWriter()); /*3*/ amf0Writers.Add(typeof(DBNull), new AMF0NullWriter()); /*5 6*/ amf0Writers.Add(typeof(Array), new AMF0ArrayWriter()); /*10*/ amf0Writers.Add(typeof(DateTime), new AMF0DateTimeWriter()); /*11*/ amf0Writers.Add(typeof(XmlDocument), new AMF0XmlDocumentWriter()); /*15*/ //AMF3 Dictionary <Type, IAMFWriter> amf3Writers = new Dictionary <Type, IAMFWriter>(); amf3Writers.Add(typeof(DBNull), new AMF3DBNullWriter()); /*0 1*/ amf3Writers.Add(typeof(bool), new AMF3BooleanWriter()); /*2 3*/ AMF3IntWriter amf3IntWriter = new AMF3IntWriter(); /*4*/ amf3Writers.Add(typeof(SByte), amf3IntWriter); amf3Writers.Add(typeof(Byte), amf3IntWriter); amf3Writers.Add(typeof(Int16), amf3IntWriter); amf3Writers.Add(typeof(UInt16), amf3IntWriter); amf3Writers.Add(typeof(Int32), amf3IntWriter); amf3Writers.Add(typeof(UInt32), amf3IntWriter); AMF3DoubleWriter amf3DoubleWriter = new AMF3DoubleWriter(); /*5*/ amf3Writers.Add(typeof(Int64), amf3DoubleWriter); amf3Writers.Add(typeof(UInt64), amf3DoubleWriter); amf3Writers.Add(typeof(Single), amf3DoubleWriter); amf3Writers.Add(typeof(Double), amf3DoubleWriter); amf3Writers.Add(typeof(Decimal), amf3DoubleWriter); amf3Writers.Add(typeof(string), new AMF3StringWriter()); /*6*/ amf3Writers.Add(typeof(XmlDocument), new AMF3XmlDocumentWriter()); /*7 11*/ amf3Writers.Add(typeof(DateTime), new AMF3DateTimeWriter()); /*8*/ amf3Writers.Add(typeof(Array), new AMF3ArrayWriter()); /*9*/ amf3Writers.Add(typeof(ASObject), new AMF3ASObjectWriter()); /*10*/ amf3Writers.Add(typeof(ByteArray), new AMF3ByteArrayWriter()); /*12*/ amf3Writers.Add(typeof(byte[]), new AMF3ByteArrayWriter()); amf3Writers.Add(typeof(List <int>), new AMF3IntVectorWriter()); /*13*/ amf3Writers.Add(typeof(IList <int>), new AMF3IntVectorWriter()); amf3Writers.Add(typeof(List <uint>), new AMF3UIntVectorWriter()); /*14*/ amf3Writers.Add(typeof(IList <uint>), new AMF3UIntVectorWriter()); amf3Writers.Add(typeof(List <double>), new AMF3DoubleVectorWriter()); /*15*/ amf3Writers.Add(typeof(IList <double>), new AMF3DoubleVectorWriter()); //未处理bool及其它数据类型 amf3Writers.Add(typeof(List <string>), new AMF3ObjectVectorWriter()); /*16*/ amf3Writers.Add(typeof(IList <string>), new AMF3ObjectVectorWriter()); AmfWriterTable = new Dictionary <Type, IAMFWriter>[4] { amf0Writers, null, null, amf3Writers }; //类型转换 typeToCustomClass.Add(typeof(ArrayCollection).FullName, "flex.messaging.io.ArrayCollection"); }