public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); IXmlDocument xmlDocument = null; IXmlNode xmlNode = null; if (typeof(XmlNode).IsAssignableFrom(objectType)) { if (objectType != typeof(XmlDocument)) { throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments"); } XmlDocument document = new XmlDocument(); xmlDocument = new XmlDocumentWrapper(document); xmlNode = xmlDocument; } if (xmlDocument == null || xmlNode == null) { throw new JsonSerializationException("Unexpected type when converting XML: " + objectType); } if (reader.TokenType != JsonToken.StartObject) { throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object."); } if (!string.IsNullOrEmpty(DeserializeRootElementName)) { ReadElement(reader, xmlDocument, xmlNode, DeserializeRootElementName, manager); } else { reader.Read(); DeserializeNode(reader, xmlDocument, manager, xmlNode); } return(xmlDocument.WrappedNode); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return(null); } XmlNamespaceManager xmlNamespaceManagers = new XmlNamespaceManager(new NameTable()); IXmlDocument xDocumentWrapper = null; IXmlNode xmlNode = null; if (typeof(XObject).IsAssignableFrom(objectType)) { if (objectType != typeof(XDocument) && objectType != typeof(XElement)) { throw new JsonSerializationException("XmlNodeConverter only supports deserializing XDocument or XElement."); } xDocumentWrapper = new XDocumentWrapper(new XDocument()); xmlNode = xDocumentWrapper; } if (typeof(XmlNode).IsAssignableFrom(objectType)) { if (objectType != typeof(XmlDocument)) { throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments"); } xDocumentWrapper = new XmlDocumentWrapper(new XmlDocument() { XmlResolver = null }); xmlNode = xDocumentWrapper; } if (xDocumentWrapper == null || xmlNode == null) { throw new JsonSerializationException(string.Concat("Unexpected type when converting XML: ", objectType)); } if (reader.TokenType != JsonToken.StartObject) { throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object."); } if (string.IsNullOrEmpty(this.DeserializeRootElementName)) { reader.Read(); this.DeserializeNode(reader, xDocumentWrapper, xmlNamespaceManagers, xmlNode); } else { this.ReadElement(reader, xDocumentWrapper, xmlNode, this.DeserializeRootElementName, xmlNamespaceManagers); } if (objectType != typeof(XElement)) { return(xDocumentWrapper.WrappedNode); } XElement wrappedNode = (XElement)xDocumentWrapper.DocumentElement.WrappedNode; wrappedNode.Remove(); return(wrappedNode); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return(null); } XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); IXmlDocument document = null; IXmlNode currentNode = null; if (typeof(XObject).IsAssignableFrom(objectType)) { if ((objectType != typeof(XDocument)) && (objectType != typeof(XElement))) { throw new JsonSerializationException("XmlNodeConverter only supports deserializing XDocument or XElement."); } document = new XDocumentWrapper(new XDocument()); currentNode = document; } if (typeof(System.Xml.XmlNode).IsAssignableFrom(objectType)) { if (objectType != typeof(XmlDocument)) { throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments"); } XmlDocument document1 = new XmlDocument { XmlResolver = null }; document = new XmlDocumentWrapper(document1); currentNode = document; } if ((document == null) || (currentNode == null)) { throw new JsonSerializationException("Unexpected type when converting XML: " + objectType); } if (reader.TokenType != JsonToken.StartObject) { throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object."); } if (!string.IsNullOrEmpty(this.DeserializeRootElementName)) { this.ReadElement(reader, document, currentNode, this.DeserializeRootElementName, manager); } else { reader.Read(); this.DeserializeNode(reader, document, manager, currentNode); } if (objectType == typeof(XElement)) { XElement wrappedNode = (XElement)document.DocumentElement.WrappedNode; wrappedNode.Remove(); return(wrappedNode); } return(document.WrappedNode); }
/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="JsonReader"/> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns>The object value.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); IXmlDocument document = null; IXmlNode rootNode = null; #if !(UNITY_ANDROID || (UNITY_IOS || UNITY_WEBGL || UNITY_XBOXONE || UNITY_XBOX360 || UNITY_PS4 || UNITY_PS3 || UNITY_WII || UNITY_IPHONE)) if (typeof(XmlNode).IsAssignableFrom(objectType)) { if (objectType != typeof(XmlDocument)) { throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments"); } XmlDocument d = new XmlDocument(); document = new XmlDocumentWrapper(d); rootNode = document; } #endif if (document == null || rootNode == null) { throw new JsonSerializationException("Unexpected type when converting XML: " + objectType); } if (reader.TokenType != JsonToken.StartObject) { throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object."); } if (!string.IsNullOrEmpty(DeserializeRootElementName)) { ReadElement(reader, document, rootNode, DeserializeRootElementName, manager); } else { reader.Read(); DeserializeNode(reader, document, manager, rootNode); } return(document.WrappedNode); }
/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="JsonReader"/> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns>The object value.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); IXmlDocument document = null; IXmlNode rootNode = null; #if !NET20 if (typeof(XObject).IsAssignableFrom(objectType)) { if (objectType != typeof (XDocument) && objectType != typeof (XElement)) throw new JsonSerializationException("XmlNodeConverter only supports deserializing XDocument or XElement."); XDocument d = new XDocument(); document = new XDocumentWrapper(d); rootNode = document; } #endif #if !(SILVERLIGHT || NETFX_CORE) if (typeof(XmlNode).IsAssignableFrom(objectType)) { if (objectType != typeof (XmlDocument)) throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments"); XmlDocument d = new XmlDocument(); document = new XmlDocumentWrapper(d); rootNode = document; } #endif if (document == null || rootNode == null) throw new JsonSerializationException("Unexpected type when converting XML: " + objectType); if (reader.TokenType != JsonToken.StartObject) throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object."); if (!string.IsNullOrEmpty(DeserializeRootElementName)) { //rootNode = document.CreateElement(DeserializeRootElementName); //document.AppendChild(rootNode); ReadElement(reader, document, rootNode, DeserializeRootElementName, manager); } else { reader.Read(); DeserializeNode(reader, document, manager, rootNode); } #if !NET20 if (objectType == typeof(XElement)) { XElement element = (XElement)document.DocumentElement.WrappedNode; element.Remove(); return element; } #endif return document.WrappedNode; }
/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="JsonReader"/> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns>The object value.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); IXmlDocument document = null; IXmlNode rootNode = null; #if !(UNITY_ANDROID || (UNITY_IOS || UNITY_IPHONE)) if (typeof(XmlNode).IsAssignableFrom(objectType)) { if (objectType != typeof (XmlDocument)) throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments"); XmlDocument d = new XmlDocument(); document = new XmlDocumentWrapper(d); rootNode = document; } #endif if (document == null || rootNode == null) throw new JsonSerializationException("Unexpected type when converting XML: " + objectType); if (reader.TokenType != JsonToken.StartObject) throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object."); if (!string.IsNullOrEmpty(DeserializeRootElementName)) { ReadElement(reader, document, rootNode, DeserializeRootElementName, manager); } else { reader.Read(); DeserializeNode(reader, document, manager, rootNode); } return document.WrappedNode; }
// Token: 0x060006E2 RID: 1762 // RVA: 0x000380E8 File Offset: 0x000362E8 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return null; } XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); IXmlDocument xmlDocument = null; IXmlNode xmlNode = null; if (typeof(XmlNode).IsAssignableFrom(objectType)) { if (objectType != typeof(XmlDocument)) { throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments"); } xmlDocument = new XmlDocumentWrapper(new XmlDocument { XmlResolver = null }); xmlNode = xmlDocument; } if (xmlDocument == null || xmlNode == null) { throw new JsonSerializationException("Unexpected type when converting XML: " + objectType); } if (reader.TokenType != JsonToken.StartObject) { throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object."); } if (!string.IsNullOrEmpty(this.DeserializeRootElementName)) { this.ReadElement(reader, xmlDocument, xmlNode, this.DeserializeRootElementName, manager); } else { reader.Read(); this.DeserializeNode(reader, xmlDocument, manager, xmlNode); } return xmlDocument.WrappedNode; }
/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="JsonReader"/> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns>The object value.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); IXmlDocument document; IXmlNode rootNode; if (typeof(XmlNode).IsAssignableFrom(objectType)) { if (objectType != typeof(XmlDocument)) { throw new JsonSerializationException("XmlNodeConverter only supports deserializing XmlDocuments"); } XmlDocument d = new XmlDocument(); document = new XmlDocumentWrapper(d); rootNode = document; } #if !NET20 else if (typeof(XObject).IsAssignableFrom(objectType)) { if (objectType != typeof(XDocument) && objectType != typeof(XElement)) { throw new JsonSerializationException("XmlNodeConverter only supports deserializing XDocument or XElement."); } XDocument d = new XDocument(); document = new XDocumentWrapper(d); rootNode = document; } #endif else { throw new JsonSerializationException("Unexpected type when converting XML: " + objectType); } if (reader.TokenType != JsonToken.StartObject) { throw new JsonSerializationException("XmlNodeConverter can only convert JSON that begins with an object."); } if (!string.IsNullOrEmpty(DeserializeRootElementName)) { //rootNode = document.CreateElement(DeserializeRootElementName); //document.AppendChild(rootNode); ReadElement(reader, document, rootNode, DeserializeRootElementName, manager); } else { reader.Read(); DeserializeNode(reader, document, manager, rootNode); } #if !NET20 if (objectType == typeof(XElement)) { XElement element = (XElement)document.DocumentElement.WrappedNode; element.Remove(); return(element); } #endif return(document.WrappedNode); }