/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param> /// <param name="serializer">The calling serializer.</param> /// <param name="value">The value.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { IXmlNode node; if (value is XmlNode) { node = new XmlNodeWrapper((XmlNode)value); } #if !NET20 else if (value is XObject) { node = XContainerWrapper.WrapNode((XObject)value); } #endif else { throw new ArgumentException("Value must be an XmlNode", "value"); } XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable()); PushParentNamespaces(node, manager); writer.WriteStartObject(); SerializeNode(writer, node, manager, true); writer.WriteEndObject(); }
private IXmlNode WrapXml(object value) { if (value is XObject) { return(XContainerWrapper.WrapNode((XObject)value)); } throw new ArgumentException("Value must be an XML object.", "value"); }
private IXmlNode WrapXml(object value) { switch (value) { case XObject _: return(XContainerWrapper.WrapNode((XObject)value)); case XmlNode _: return(XmlNodeWrapper.WrapNode((XmlNode)value)); default: throw new ArgumentException("Value must be an XML object.", nameof(value)); } }