tangxu
2024-10-22 6a07c4c846ffbb1e93afdf0260e123e4c145f419
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System.Collections.Generic;
using System.Xml.Linq;
 
namespace DPumpHydr.WinFrmUI.WenSkin.Json.Converters
{
    internal class XContainerWrapper : XObjectWrapper
    {
        private List<IXmlNode> _childNodes;
 
        private XContainer Container => (XContainer)base.WrappedNode;
 
        public override List<IXmlNode> ChildNodes
        {
            get
            {
                if (_childNodes == null)
                {
                    _childNodes = new List<IXmlNode>();
                    foreach (XNode item in Container.Nodes())
                    {
                        _childNodes.Add(WrapNode(item));
                    }
                }
                return _childNodes;
            }
        }
 
        public override IXmlNode ParentNode
        {
            get
            {
                if (Container.Parent == null)
                {
                    return null;
                }
                return WrapNode(Container.Parent);
            }
        }
 
        public XContainerWrapper(XContainer container)
            : base(container)
        {
        }
 
        internal static IXmlNode WrapNode(XObject node)
        {
            if (node is XDocument)
            {
                return new XDocumentWrapper((XDocument)node);
            }
            if (node is XElement)
            {
                return new XElementWrapper((XElement)node);
            }
            if (node is XContainer)
            {
                return new XContainerWrapper((XContainer)node);
            }
            if (node is XProcessingInstruction)
            {
                return new XProcessingInstructionWrapper((XProcessingInstruction)node);
            }
            if (node is XText)
            {
                return new XTextWrapper((XText)node);
            }
            if (node is XComment)
            {
                return new XCommentWrapper((XComment)node);
            }
            if (node is XAttribute)
            {
                return new XAttributeWrapper((XAttribute)node);
            }
            if (node is XDocumentType)
            {
                return new XDocumentTypeWrapper((XDocumentType)node);
            }
            return new XObjectWrapper(node);
        }
 
        public override IXmlNode AppendChild(IXmlNode newChild)
        {
            Container.Add(newChild.WrappedNode);
            _childNodes = null;
            return newChild;
        }
    }
}