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); }
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); } } }
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); }
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; }
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; }
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; }
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); } } }
public override void SetMemberValue (object owner, JsonSerializationReader jsr) { field.SetValue (owner, jsr.ReadObject (this.Type)); }
public override void SetMemberValue(object owner, JsonSerializationReader jsr) { field.SetValue(owner, jsr.ReadObject(this.Type)); }