Inheritance: XObjectWrapper
コード例 #1
0
        /// <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();
        }
コード例 #2
0
        private IXmlNode WrapXml(object value)
        {
            if (value is XObject)
            {
                return(XContainerWrapper.WrapNode((XObject)value));
            }

            throw new ArgumentException("Value must be an XML object.", "value");
        }
コード例 #3
0
        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));
            }
        }