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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System.Collections.Generic;
using System.Xml;
 
namespace DPumpHydr.WinFrmUI.WenSkin.Json.Converters
{
    internal class XmlNodeWrapper : IXmlNode
    {
        private readonly XmlNode _node;
 
        private List<IXmlNode> _childNodes;
 
        private List<IXmlNode> _attributes;
 
        public object WrappedNode => _node;
 
        public XmlNodeType NodeType => _node.NodeType;
 
        public virtual string LocalName => _node.LocalName;
 
        public List<IXmlNode> ChildNodes
        {
            get
            {
                if (_childNodes == null)
                {
                    _childNodes = new List<IXmlNode>(_node.ChildNodes.Count);
                    foreach (XmlNode childNode in _node.ChildNodes)
                    {
                        _childNodes.Add(WrapNode(childNode));
                    }
                }
                return _childNodes;
            }
        }
 
        public List<IXmlNode> Attributes
        {
            get
            {
                if (_node.Attributes == null)
                {
                    return null;
                }
                if (_attributes == null)
                {
                    _attributes = new List<IXmlNode>(_node.Attributes.Count);
                    foreach (XmlAttribute attribute in _node.Attributes)
                    {
                        _attributes.Add(WrapNode(attribute));
                    }
                }
                return _attributes;
            }
        }
 
        public IXmlNode ParentNode
        {
            get
            {
                XmlNode xmlNode = ((_node is XmlAttribute) ? ((XmlAttribute)_node).OwnerElement : _node.ParentNode);
                if (xmlNode == null)
                {
                    return null;
                }
                return WrapNode(xmlNode);
            }
        }
 
        public string Value
        {
            get
            {
                return _node.Value;
            }
            set
            {
                _node.Value = value;
            }
        }
 
        public string NamespaceUri => _node.NamespaceURI;
 
        public XmlNodeWrapper(XmlNode node)
        {
            _node = node;
        }
 
        internal static IXmlNode WrapNode(XmlNode node)
        {
            return node.NodeType switch
            {
                XmlNodeType.Element => new XmlElementWrapper((XmlElement)node), 
                XmlNodeType.XmlDeclaration => new XmlDeclarationWrapper((XmlDeclaration)node), 
                XmlNodeType.DocumentType => new XmlDocumentTypeWrapper((XmlDocumentType)node), 
                _ => new XmlNodeWrapper(node), 
            };
        }
 
        public IXmlNode AppendChild(IXmlNode newChild)
        {
            XmlNodeWrapper xmlNodeWrapper = (XmlNodeWrapper)newChild;
            _node.AppendChild(xmlNodeWrapper._node);
            _childNodes = null;
            _attributes = null;
            return newChild;
        }
    }
}