XContainerWrapper
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
namespace Newtonsoft.Json.Converters
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
internal class XContainerWrapper : XObjectWrapper
{
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
private List<IXmlNode> _childNodes;
private XContainer Container => (XContainer)base.WrappedNode;
public override List<IXmlNode> ChildNodes {
get {
if (_childNodes == null) {
if (!HasChildNodes)
_childNodes = XmlNodeConverter.EmptyChildNodes;
else {
_childNodes = new List<IXmlNode>();
foreach (XNode item in Container.Nodes()) {
_childNodes.Add(WrapNode(item));
}
}
}
return _childNodes;
}
}
protected virtual bool HasChildNodes => Container.LastNode != null;
[System.Runtime.CompilerServices.Nullable(2)]
public override IXmlNode ParentNode {
[System.Runtime.CompilerServices.NullableContext(2)]
get {
if (Container.Parent == null)
return null;
return WrapNode(Container.Parent);
}
}
public XContainerWrapper(XContainer container)
: base(container)
{
}
internal static IXmlNode WrapNode(XObject node)
{
XDocument xDocument = node as XDocument;
if (xDocument != null)
return new XDocumentWrapper(xDocument);
XElement xElement = node as XElement;
if (xElement != null)
return new XElementWrapper(xElement);
XContainer xContainer = node as XContainer;
if (xContainer != null)
return new XContainerWrapper(xContainer);
XProcessingInstruction xProcessingInstruction = node as XProcessingInstruction;
if (xProcessingInstruction != null)
return new XProcessingInstructionWrapper(xProcessingInstruction);
XText xText = node as XText;
if (xText != null)
return new XTextWrapper(xText);
XComment xComment = node as XComment;
if (xComment != null)
return new XCommentWrapper(xComment);
XAttribute xAttribute = node as XAttribute;
if (xAttribute != null)
return new XAttributeWrapper(xAttribute);
XDocumentType xDocumentType = node as XDocumentType;
if (xDocumentType != null)
return new XDocumentTypeWrapper(xDocumentType);
return new XObjectWrapper(node);
}
public override IXmlNode AppendChild(IXmlNode newChild)
{
Container.Add(newChild.WrappedNode);
_childNodes = null;
return newChild;
}
}
}