public override object Deserialize(XmlReader reader, SerializationContext state) { var retval = base.Deserialize(reader, state); if (listType.IsArray) { int count; if (retval is System.Collections.IList) { count = ((System.Collections.IList)retval).Count; } else { count = (int)retval.GetType().GetProperty("Count", BindingFlags.Instance | BindingFlags.Public).GetValue(retval, new object[0]); } var array = Array.CreateInstance(listType.GetElementType(), count); state.DeserializationStart(retval); if (retval is System.Collections.IList) { ((System.Collections.IList)retval).CopyTo(array, 0); } else { retval.GetType().GetMethod ( "CopyTo", BindingFlags.Instance | BindingFlags.Public ).Invoke(retval, new object[] { array, 0 }); } retval = array; } state.DeserializationEnd(retval); return retval; }
public override object Deserialize(XmlReader reader, SerializationContext state) { var retval = base.Deserialize(reader, state); if (listType.IsArray) { int count; if (retval is System.Collections.IList) { count = ((System.Collections.IList)retval).Count; } else { count = (int)retval.GetType().GetProperty("Count", BindingFlags.Instance | BindingFlags.Public).GetValue(retval, new object[0]); } var array = Array.CreateInstance(listType.GetElementType(), count); state.DeserializationStart(retval); if (retval is System.Collections.IList) { ((System.Collections.IList)retval).CopyTo(array, 0); } else { retval.GetType().GetMethod ( "CopyTo", BindingFlags.Instance | BindingFlags.Public ).Invoke(retval, new object[] { array, 0 }); } retval = array; } state.DeserializationEnd(retval); return retval; }
public virtual object Deserialize(object instance, XmlReader reader, SerializationContext state) { var obj = instance; state.DeserializationStart(obj); if (reader.AttributeCount > 0) { for (var i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); DeserializeAttribute(obj, reader, state); } reader.MoveToElement(); } // If there's no subelements then exit if (reader.IsEmptyElement) { reader.ReadStartElement(); return(obj); } reader.ReadStartElement(); // Read elements while (true) { XmlReaderHelper.ReadUntilAnyTypesReached(reader, new XmlNodeType[] { XmlNodeType.Element, XmlNodeType.EndElement, XmlNodeType.Text, XmlNodeType.CDATA }); if (reader.NodeType == XmlNodeType.Element) { DeserializeElement(obj, reader, state); //XmlReaderHelper.ReadAndConsumeMatchingEndElement(reader); } else if (reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.CDATA) { if (reader.HasValue) { DeserializeText(obj, reader, state); reader.Read(); } } else { if (reader.NodeType == XmlNodeType.EndElement) { reader.ReadEndElement(); } else { // Unknown element } break; } } state.DeserializationEnd(obj); return(obj); }
public virtual object Deserialize(object instance, XmlReader reader, SerializationContext state) { var obj = instance; state.DeserializationStart(obj); if (reader.AttributeCount > 0) { for (var i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); DeserializeAttribute(obj, reader, state); } reader.MoveToElement(); } // If there's no subelements then exit if (reader.IsEmptyElement) { reader.ReadStartElement(); return obj; } reader.ReadStartElement(); // Read elements while (true) { XmlReaderHelper.ReadUntilAnyTypesReached(reader, new XmlNodeType[] { XmlNodeType.Element, XmlNodeType.EndElement, XmlNodeType.Text, XmlNodeType.CDATA }); if (reader.NodeType == XmlNodeType.Element) { DeserializeElement(obj, reader, state); //XmlReaderHelper.ReadAndConsumeMatchingEndElement(reader); } else if (reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.CDATA) { if (reader.HasValue) { DeserializeText(obj, reader, state); reader.Read(); } } else { if (reader.NodeType == XmlNodeType.EndElement) { reader.ReadEndElement(); } else { // Unknown element } break; } } state.DeserializationEnd(obj); return obj; }