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
using System.Collections.Generic;
using System.Xml.Linq;
 
namespace DPumpHydr.WinFrmUI.WenSkin.Json.Converters
{
    internal class XElementWrapper : XContainerWrapper, IXmlElement, IXmlNode
    {
        private List<IXmlNode> _attributes;
 
        private XElement Element => (XElement)base.WrappedNode;
 
        public override List<IXmlNode> Attributes
        {
            get
            {
                if (_attributes == null)
                {
                    _attributes = new List<IXmlNode>();
                    foreach (XAttribute item in Element.Attributes())
                    {
                        _attributes.Add(new XAttributeWrapper(item));
                    }
                    string namespaceUri = NamespaceUri;
                    if (!string.IsNullOrEmpty(namespaceUri) && namespaceUri != ParentNode?.NamespaceUri && string.IsNullOrEmpty(GetPrefixOfNamespace(namespaceUri)))
                    {
                        bool flag = false;
                        foreach (IXmlNode attribute in _attributes)
                        {
                            if (attribute.LocalName == "xmlns" && string.IsNullOrEmpty(attribute.NamespaceUri) && attribute.Value == namespaceUri)
                            {
                                flag = true;
                            }
                        }
                        if (!flag)
                        {
                            _attributes.Insert(0, new XAttributeWrapper(new XAttribute("xmlns", namespaceUri)));
                        }
                    }
                }
                return _attributes;
            }
        }
 
        public override string Value
        {
            get
            {
                return Element.Value;
            }
            set
            {
                Element.Value = value;
            }
        }
 
        public override string LocalName => Element.Name.LocalName;
 
        public override string NamespaceUri => Element.Name.NamespaceName;
 
        public bool IsEmpty => Element.IsEmpty;
 
        public XElementWrapper(XElement element)
            : base(element)
        {
        }
 
        public void SetAttributeNode(IXmlNode attribute)
        {
            XObjectWrapper xObjectWrapper = (XObjectWrapper)attribute;
            Element.Add(xObjectWrapper.WrappedNode);
            _attributes = null;
        }
 
        public override IXmlNode AppendChild(IXmlNode newChild)
        {
            IXmlNode result = base.AppendChild(newChild);
            _attributes = null;
            return result;
        }
 
        public string GetPrefixOfNamespace(string namespaceUri)
        {
            return Element.GetPrefixOfNamespace(namespaceUri);
        }
    }
}