Ejemplo n.º 1
0
        public void WriteData(AMFWriter writer, object data)
        {
            NameObjectCollectionBase collection = data as NameObjectCollectionBase;

            object[] attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
            if (attributes != null && attributes.Length > 0)
            {
                DefaultMemberAttribute defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
                PropertyInfo           pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new Type[] { typeof(string) });
                if (pi != null)
                {
                    ASObject aso = new ASObject();

                    IEnumerator enumList = collection.Keys.GetEnumerator();

                    //为了兼容 webplayer 和手机 platform 而改掉的代码,原来的代码见后面的注释内容.
                    while (enumList.MoveNext())
                    {
                        string key   = enumList.Current as string;
                        object value = pi.GetValue(collection, new object[] { key });

                        aso.Add(key, value);
                    }
                    writer.WriteByte(AMF3TypeCode.Object);
                    writer.WriteAMF3Object(aso);
                    return;
                }
            }

            //We could not access an indexer so write out as it is.
            writer.WriteByte(AMF3TypeCode.Object);
            writer.WriteAMF3Object(data);
        }
Ejemplo n.º 2
0
        public object ReadData(AMFReader reader, ClassDefinition classDefinition)
        {
            ASObject aso = new ASObject(_typeIdentifier);

            reader.AddAMF3ObjectReference(aso);
            string key = reader.ReadAMF3String();

            aso.TypeName = _typeIdentifier;
            while (key != string.Empty)
            {
                object value = reader.ReadAMF3Data();
                aso.Add(key, value);
                key = reader.ReadAMF3String();
            }
            return(aso);
        }