public override object DeserializeEmptyContent(XmlReader reader, XmlFormatterDeserializer deserializer, string id) { var instance = CreateInstance(); HandleId(id, deserializer, instance); if (OnDeserializing != null) { OnDeserializing.Invoke(instance, new object [] { new StreamingContext(StreamingContextStates.All) }); } try { if (RuntimeType.IsArray) { return(((ArrayList)instance).ToArray(element_type)); } else { return(instance); } } finally { if (OnDeserialized != null) { OnDeserialized.Invoke(instance, new object [] { new StreamingContext(StreamingContextStates.All) }); } } }
internal void InvokeOnDeserializing(object o, StreamingContext context) { if (OnDeserializing != null) { OnDeserializing.Invoke(o, new object[] { context }); } }
internal void InvokeOnDeserializing(object o, StreamingContext context) { #if !PocketPC if (OnDeserializing != null) { OnDeserializing.Invoke(o, new object[] { context }); } #endif }
internal void InvokeOnDeserializing(object o) { #if !PocketPC && !SILVERLIGHT if (OnDeserializing != null) { OnDeserializing.Invoke(o, SerializationEventParameterValues); } #endif }
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 override object DeserializeContent(XmlReader reader, XmlFormatterDeserializer deserializer, string id) { object instance = CreateInstance(); HandleId(id, deserializer, instance); if (OnDeserializing != null) { OnDeserializing.Invoke(instance, new object [] { new StreamingContext(StreamingContextStates.All) }); } int depth = reader.NodeType == XmlNodeType.None ? reader.Depth : reader.Depth - 1; while (reader.NodeType == XmlNodeType.Element && reader.Depth > depth) { object elem = deserializer.Deserialize(element_type, reader); if (instance is IList) { ((IList)instance).Add(elem); } else if (add_method != null) { add_method.Invoke(instance, new object [] { elem }); } else { throw new NotImplementedException(String.Format("Type {0} is not supported", RuntimeType)); } reader.MoveToContent(); } try { if (RuntimeType.IsArray) { return(((ArrayList)instance).ToArray(element_type)); } return(instance); } finally { if (OnDeserialized != null) { OnDeserialized.Invoke(instance, new object [] { new StreamingContext(StreamingContextStates.All) }); } } }
object DeserializeContent(XmlReader reader, XmlFormatterDeserializer deserializer, string id, bool empty) { object instance = FormatterServices.GetUninitializedObject(RuntimeType); HandleId(id, deserializer, instance); if (OnDeserializing != null) { OnDeserializing.Invoke(instance, new object [] { new StreamingContext(StreamingContextStates.All) }); } int depth = reader.NodeType == XmlNodeType.None ? reader.Depth : reader.Depth - 1; bool [] filled = new bool [Members.Count]; bool [] nsmatched = new bool [Members.Count]; int memberInd = -1, ordered = -1; while (!empty && reader.NodeType == XmlNodeType.Element && reader.Depth > depth) { DataMemberInfo dmi = null; int i = 0; bool nsmatchedOne = false; for (; i < Members.Count; i++) // unordered { if (Members [i].Order >= 0) { break; } if (reader.LocalName == Members [i].XmlName) { memberInd = i; dmi = Members [i]; nsmatchedOne = (dmi.XmlRootNamespace == null || reader.NamespaceURI == dmi.XmlRootNamespace); if (nsmatchedOne) { break; } } } for (i = Math.Max(i, ordered); i < Members.Count; i++) // ordered { if (dmi != null) { break; } if (reader.LocalName == Members [i].XmlName) { ordered = i; memberInd = i; dmi = Members [i]; nsmatchedOne = (dmi.XmlRootNamespace == null || reader.NamespaceURI == dmi.XmlRootNamespace); if (nsmatchedOne) { break; } } } if (dmi == null) { reader.Skip(); reader.MoveToContent(); continue; } if (filled [memberInd] && nsmatched [memberInd]) { // The strictly-corresponding member (i.e. that matches namespace URI too, not only local name) already exists, so skip this element. reader.Skip(); reader.MoveToContent(); continue; } nsmatched [memberInd] = nsmatchedOne; SetValue(dmi, instance, deserializer.Deserialize(dmi.MemberType, reader)); filled [memberInd] = true; reader.MoveToContent(); } for (int i = 0; i < Members.Count; i++) { if (!filled [i] && Members [i].IsRequired) { throw MissingRequiredMember(Members [i], reader); } } if (OnDeserialized != null) { OnDeserialized.Invoke(instance, new object [] { new StreamingContext(StreamingContextStates.All) }); } return(instance); }