コード例 #1
0
        public object Deserialize(JsonSerializationReader jsr)
        {
            XmlReader reader = jsr.Reader;
            object    ret    = FormatterServices.GetUninitializedObject(type);
            Dictionary <TypeMapMember, bool> filled = new Dictionary <TypeMapMember, bool> ();

            reader.ReadStartElement();
            for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent())
            {
                bool consumed = false;
                for (int i = 0; i < members.Length; i++)
                {
                    TypeMapMember mm = members [i];
                    if (mm.Name == reader.LocalName && reader.NamespaceURI == String.Empty)
                    {
                        if (filled.ContainsKey(mm))
                        {
                            throw new SerializationException(String.Format("Object content '{0}' for '{1}' already appeared in the reader", reader.LocalName, type));
                        }
                        mm.SetMemberValue(ret, jsr.ReadObject(mm.Type));
                        filled [mm] = true;
                        consumed    = true;
                        break;
                    }
                }
                if (!consumed)
                {
                    reader.Skip();
                }
            }
            reader.ReadEndElement();
            return(ret);
        }
コード例 #2
0
ファイル: TypeMap.cs プロジェクト: zhangf911/NoahGameFrame
        public override void SetMemberValue(object owner, JsonSerializationReader jsr)
        {
            var pSetter = this.property.GetSetMethod(true);

            if (pSetter != null)
            {
                property.SetValue(owner, jsr.ReadObject(this.Type), null);
            }
            else                 // no setter
            {
                var oldValue = property.GetValue(owner, null);
                try {
                    jsr.ReadObject(this.Type, oldValue);
                } catch (MissingMethodException e) {
                    throw new InvalidDataContractException(string.Format("No set method for property '{0}' "
                                                                         + "in type '{1}'.", this.property.Name, this.property.PropertyType.FullName), e);
                }
            }
        }
コード例 #3
0
ファイル: TypeMap.cs プロジェクト: vernon016/mono
        public virtual object Deserialize(JsonSerializationReader jsr)
        {
            XmlReader reader = jsr.Reader;
            bool      isNull = reader.GetAttribute("type") == "null";

            object ret = isNull ? null : CreateInstance(type);

            if (ret != null && OnDeserializing != null)
            {
                OnDeserializing.Invoke(ret, new object [] { new StreamingContext(StreamingContextStates.All) });
            }
            Dictionary <TypeMapMember, bool> filled = new Dictionary <TypeMapMember, bool> ();

            reader.ReadStartElement();
            for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent())
            {
                bool consumed = false;
                for (int i = 0; i < members.Length; i++)
                {
                    TypeMapMember mm = members [i];
                    if (mm.Name == reader.LocalName && reader.NamespaceURI == String.Empty)
                    {
                        if (filled.ContainsKey(mm))
                        {
                            throw new SerializationException(String.Format("Object content '{0}' for '{1}' already appeared in the reader", reader.LocalName, type));
                        }
                        mm.SetMemberValue(ret, jsr.ReadObject(mm.Type));
                        filled [mm] = true;
                        consumed    = true;
                        break;
                    }
                }
                if (!consumed)
                {
                    reader.Skip();
                }
            }
            reader.ReadEndElement();
            if (ret != null && OnDeserialized != null)
            {
                OnDeserialized.Invoke(ret, new object [] { new StreamingContext(StreamingContextStates.All) });
            }
            return(ret);
        }
コード例 #4
0
ファイル: TypeMap.cs プロジェクト: GirlD/mono
		public virtual object Deserialize (JsonSerializationReader jsr)
		{
			XmlReader reader = jsr.Reader;
			bool isNull = reader.GetAttribute ("type") == "null";

			object ret = isNull ? null : CreateInstance (type);
			if (ret != null && OnDeserializing != null)
				OnDeserializing.Invoke (ret, new object [] {new StreamingContext (StreamingContextStates.All)});
			Dictionary<TypeMapMember,bool> filled = new Dictionary<TypeMapMember,bool> ();

			reader.ReadStartElement ();
			for (reader.MoveToContent (); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
				bool consumed = false;
				for (int i = 0; i < members.Length; i++) {
					TypeMapMember mm = members [i];
					if (mm.Name == reader.LocalName && reader.NamespaceURI == String.Empty) {
						if (filled.ContainsKey (mm))
							throw new SerializationException (String.Format ("Object content '{0}' for '{1}' already appeared in the reader", reader.LocalName, type));
						mm.SetMemberValue (ret, jsr.ReadObject (mm.Type));
						filled [mm] = true;
						consumed = true;
						break;
					}
				}
				if (!consumed)
					reader.Skip ();
			}
			reader.ReadEndElement ();
			if (ret != null && OnDeserialized != null)
				OnDeserialized.Invoke (ret, new object [] {new StreamingContext (StreamingContextStates.All)});
			return ret;
		}
コード例 #5
0
ファイル: TypeMap.cs プロジェクト: andresmoschini/SharpPodder
        public object Deserialize(JsonSerializationReader jsr)
        {
            XmlReader reader = jsr.Reader;
            object ret = FormatterServices.GetUninitializedObject (type);
            Dictionary<TypeMapMember,bool> filled = new Dictionary<TypeMapMember,bool> ();

            reader.ReadStartElement ();
            for (reader.MoveToContent (); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
                bool consumed = false;
                for (int i = 0; i < members.Length; i++) {
                    TypeMapMember mm = members [i];
                    if (mm.Name == reader.LocalName && reader.NamespaceURI == String.Empty) {
                        if (filled.ContainsKey (mm))
                            throw new SerializationException (String.Format ("Object content '{0}' for '{1}' already appeared in the reader", reader.LocalName, type));
                        mm.SetMemberValue (ret, jsr.ReadObject (mm.Type));
                        filled [mm] = true;
                        consumed = true;
                        break;
                    }
                }
                if (!consumed)
                    reader.Skip ();
            }
            reader.ReadEndElement ();
            return ret;
        }
コード例 #6
0
ファイル: TypeMap.cs プロジェクト: atsushieno/slingr
        public object Deserialize(JsonSerializationReader jsr)
        {
            XmlReader reader = jsr.Reader;
            #if NET_2_1
            // should it reject non-public constructor?
            object ret = Activator.CreateInstance (type);
            #else
            object ret = Activator.CreateInstance (type, true);
            #endif
            Dictionary<TypeMapMember,bool> filled = new Dictionary<TypeMapMember,bool> ();

            reader.ReadStartElement ();
            for (reader.MoveToContent (); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
                bool consumed = false;
                for (int i = 0; i < members.Length; i++) {
                    TypeMapMember mm = members [i];
                    if (mm.Name == reader.LocalName && reader.NamespaceURI == String.Empty) {
                        if (filled.ContainsKey (mm))
                            throw new SerializationException (String.Format ("Object content '{0}' for '{1}' already appeared in the reader", reader.LocalName, type));
                        mm.SetMemberValue (ret, jsr.ReadObject (mm.Type));
                        filled [mm] = true;
                        consumed = true;
                        break;
                    }
                }
                if (!consumed)
                    reader.Skip ();
            }
            reader.ReadEndElement ();
            return ret;
        }
コード例 #7
0
ファイル: TypeMap.cs プロジェクト: nlhepler/mono
		public override void SetMemberValue (object owner, JsonSerializationReader jsr)
		{
			var pSetter = this.property.GetSetMethod (true);
			if (pSetter != null) {
				property.SetValue (owner, jsr.ReadObject (this.Type), null);
				
			} else { // no setter
				var oldValue = property.GetValue (owner, null);
				try {
					jsr.ReadObject (this.Type, oldValue);
				} catch (MissingMethodException e) {
					throw new InvalidDataContractException (string.Format ("No set method for property '{0}' "
						+ "in type '{1}'.", this.property.Name, this.property.PropertyType.FullName), e);
				}
			}
		}
コード例 #8
0
ファイル: TypeMap.cs プロジェクト: nlhepler/mono
		public override void SetMemberValue (object owner, JsonSerializationReader jsr)
		{
			field.SetValue (owner, jsr.ReadObject (this.Type));
		}
コード例 #9
0
ファイル: TypeMap.cs プロジェクト: zhangf911/NoahGameFrame
 public override void SetMemberValue(object owner, JsonSerializationReader jsr)
 {
     field.SetValue(owner, jsr.ReadObject(this.Type));
 }