示例#1
0
        internal void WriteAmf0TypedObject(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            if (this.SerializationContext == null)
            {
                throw new NullReferenceException("Cannot serialize objects because no SerializationContext was provided.");
            }
            this.AddAmf0Reference(obj);
            Type             type             = obj.GetType();
            string           fullName         = type.FullName;
            ClassDescription classDescription = this.SerializationContext.GetClassDescription(type, obj);

            if (classDescription == null)
            {
                throw new SerializationException(string.Format("Couldn't get class description for {0}.", (object)fullName));
            }
            this.WriteMarker(Amf0TypeMarkers.TypedObject);
            this.WriteUtfPrefixed(classDescription.Name);
            foreach (IMemberWrapper member in classDescription.Members)
            {
                this.WriteUtfPrefixed(member.SerializedName);
                this.WriteAmf0Item(member.GetValue(obj));
            }
            this.WriteUInt16((ushort)0);
            this.WriteMarker(Amf0TypeMarkers.ObjectEnd);
        }
示例#2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            object                       instance         = MethodFactory.CreateInstance(destinationType);
            ClassDescription             classDescription = this._serializationContext.GetClassDescription(destinationType, instance);
            IDictionary <string, object> dictionary       = value as IDictionary <string, object>;

            if (dictionary == null)
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }
            foreach (KeyValuePair <string, object> keyValuePair in (IEnumerable <KeyValuePair <string, object> >)dictionary)
            {
                IMemberWrapper memberWrapper;
                if (classDescription.TryGetMember(keyValuePair.Key, out memberWrapper))
                {
                    memberWrapper.SetValue(instance, keyValuePair.Value);
                }
            }
            return(instance);
        }
示例#3
0
        internal void WriteAmf3Object(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            if (this.SerializationContext == null)
            {
                throw new NullReferenceException("Cannot serialize objects because no SerializationContext was provided.");
            }
            if (this.WriteAmf3ReferenceOnExistence(obj))
            {
                return;
            }
            this.AddAmf3Reference(obj);
            ClassDescription classDescription = this.SerializationContext.GetClassDescription(obj);
            int num;

            if (this._amf3ClassDefinitionReferences.TryGetValue(classDescription, out num))
            {
                this.WriteAmf3InlineHeader(num << 1);
            }
            else if (obj is AsObject && !(obj as AsObject).IsTyped)
            {
                this.WriteByte((byte)11);
                this.WriteByte((byte)1);
                foreach (KeyValuePair <string, object> keyValuePair in obj as AsObject)
                {
                    this.WriteAmf3Utf(keyValuePair.Key);
                    this.WriteAmf3Item(keyValuePair.Value);
                }
                this.WriteByte((byte)1);
            }
            else
            {
                this._amf3ClassDefinitionReferences.Add(classDescription, this._amf3ClassDefinitionReferences.Count);
                this.WriteAmf3InlineHeader(((classDescription.Members.Length << 1 | (classDescription.IsDynamic ? 1 : 0)) << 1 | (classDescription.IsExternalizable ? 1 : 0)) << 1 | 1);
                this.WriteAmf3Utf(classDescription.Name);
                if (classDescription.IsExternalizable)
                {
                    IExternalizable externalizable = obj as IExternalizable;
                    if (externalizable == null)
                    {
                        throw new SerializationException("Externalizable class does not implement IExternalizable");
                    }
                    DataOutput dataOutput = new DataOutput(this);
                    externalizable.WriteExternal((IDataOutput)dataOutput);
                }
                else
                {
                    foreach (IMemberWrapper member in classDescription.Members)
                    {
                        this.WriteAmf3Utf(member.SerializedName);
                    }
                    foreach (IMemberWrapper member in classDescription.Members)
                    {
                        this.WriteAmf3Item(member.GetValue(obj));
                    }
                    if (!classDescription.IsDynamic)
                    {
                        return;
                    }
                    IDictionary <string, object> dictionary = obj as IDictionary <string, object>;
                    if (dictionary == null)
                    {
                        throw new SerializationException("Dynamic class does not implement IDictionary");
                    }
                    foreach (KeyValuePair <string, object> keyValuePair in (IEnumerable <KeyValuePair <string, object> >)dictionary)
                    {
                        this.WriteAmf3Utf(keyValuePair.Key);
                        this.WriteAmf3Item(keyValuePair.Value);
                    }
                    this.WriteAmf3Utf(string.Empty);
                }
            }
        }
示例#4
0
 ClassDescription ClassReferenceAdd(ClassDescription value)
 {
     refClasses.Add(value);
     return(value);
 }