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 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 TypeMap (Type type, string element, TypeMapMember [] orderedMembers) { this.type = type; this.element = element; this.members = orderedMembers; foreach (var mi in type.GetMethods (binding_flags)) { if (mi.GetCustomAttributes (typeof (OnDeserializingAttribute), false).Length > 0) OnDeserializing = mi; else if (mi.GetCustomAttributes (typeof (OnDeserializedAttribute), false).Length > 0) OnDeserialized = mi; else if (mi.GetCustomAttributes (typeof (OnSerializingAttribute), false).Length > 0) OnSerializing = mi; else if (mi.GetCustomAttributes (typeof (OnSerializedAttribute), false).Length > 0) OnSerialized = mi; } }
public TypeMap(Type type, string element, TypeMapMember [] orderedMembers) { this.type = type; this.element = element; this.members = orderedMembers; }