Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlElementList.cs
Go to the documentation of this file.
2
3namespace System.Xml;
4
5internal sealed class XmlElementList : XmlNodeList
6{
7 private readonly string _asterisk;
8
9 private int _changeCount;
10
11 private readonly string _name;
12
13 private string _localName;
14
15 private string _namespaceURI;
16
17 private readonly XmlNode _rootNode;
18
19 private int _curInd;
20
22
23 private bool _empty;
24
25 private bool _atomized;
26
27 private int _matchCount;
28
30
31 internal int ChangeCount => _changeCount;
32
33 public override int Count
34 {
35 get
36 {
37 if (_empty)
38 {
39 return 0;
40 }
41 if (_matchCount < 0)
42 {
43 int num = 0;
46 while ((n = GetMatchingNode(n, bNext: true)) != null)
47 {
48 num++;
49 }
51 {
52 return num;
53 }
54 _matchCount = num;
55 }
56 return _matchCount;
57 }
58 }
59
60 private XmlElementList(XmlNode parent)
61 {
62 _rootNode = parent;
63 _curInd = -1;
65 _changeCount = 0;
66 _empty = false;
67 _atomized = true;
68 _matchCount = -1;
70 }
71
73 {
74 Dispose(disposing: false);
75 }
76
78 {
79 if (!_atomized)
80 {
84 _atomized = true;
85 }
86 if (IsMatch(args.Node))
87 {
89 _curInd = -1;
91 if (args.Action == XmlNodeChangedAction.Insert)
92 {
93 _empty = false;
94 }
95 }
96 _matchCount = -1;
97 }
98
99 internal XmlElementList(XmlNode parent, string name)
100 : this(parent)
101 {
103 _asterisk = nameTable.Add("*");
104 _name = nameTable.Add(name);
105 _localName = null;
106 _namespaceURI = null;
107 }
108
109 internal XmlElementList(XmlNode parent, string localName, string namespaceURI)
110 : this(parent)
111 {
113 _asterisk = nameTable.Add("*");
114 _localName = nameTable.Get(localName);
116 if (_localName == null || _namespaceURI == null)
117 {
118 _empty = true;
119 _atomized = false;
120 _localName = localName;
122 }
123 _name = null;
124 }
125
127 {
128 XmlNode xmlNode = curNode.FirstChild;
129 if (xmlNode == null)
130 {
131 xmlNode = curNode;
132 while (xmlNode != null && xmlNode != _rootNode && xmlNode.NextSibling == null)
133 {
135 }
136 if (xmlNode != null && xmlNode != _rootNode)
137 {
139 }
140 }
141 if (xmlNode == _rootNode)
142 {
143 xmlNode = null;
144 }
145 return xmlNode;
146 }
147
149 {
151 while (xmlNode != null && xmlNode.LastChild != null)
152 {
154 }
155 if (xmlNode == null)
156 {
157 xmlNode = curNode.ParentNode;
158 }
159 if (xmlNode == _rootNode)
160 {
161 xmlNode = null;
162 }
163 return xmlNode;
164 }
165
166 private bool IsMatch(XmlNode curNode)
167 {
168 if (curNode.NodeType == XmlNodeType.Element)
169 {
170 if (_name != null)
171 {
172 if (Ref.Equal(_name, _asterisk) || Ref.Equal(curNode.Name, _name))
173 {
174 return true;
175 }
176 }
178 {
179 return true;
180 }
181 }
182 return false;
183 }
184
186 {
187 XmlNode xmlNode = n;
188 do
189 {
191 }
192 while (xmlNode != null && !IsMatch(xmlNode));
193 return xmlNode;
194 }
195
197 {
198 XmlNode xmlNode = n;
199 for (int i = 0; i < nCount; i++)
200 {
202 if (xmlNode == null)
203 {
204 return null;
205 }
206 }
207 return xmlNode;
208 }
209
211 {
212 if (_empty)
213 {
214 return null;
215 }
216 XmlNode n2 = ((n == null) ? _rootNode : n);
217 return GetMatchingNode(n2, bNext: true);
218 }
219
220 public override XmlNode Item(int index)
221 {
222 if (_rootNode == null || index < 0)
223 {
224 return null;
225 }
226 if (_empty)
227 {
228 return null;
229 }
230 if (_curInd == index)
231 {
232 return _curElem;
233 }
234 int num = index - _curInd;
235 bool bNext = num > 0;
236 if (num < 0)
237 {
238 num = -num;
239 }
241 if ((nthMatchingNode = GetNthMatchingNode(_curElem, bNext, num)) != null)
242 {
243 _curInd = index;
245 return _curElem;
246 }
247 return null;
248 }
249
250 public override IEnumerator GetEnumerator()
251 {
252 if (_empty)
253 {
254 return new XmlEmptyElementListEnumerator(this);
255 }
256 return new XmlElementListEnumerator(this);
257 }
258
259 protected override void PrivateDisposeNodeList()
260 {
261 GC.SuppressFinalize(this);
262 Dispose(disposing: true);
263 }
264
265 private void Dispose(bool disposing)
266 {
267 if (_listener != null)
268 {
269 if (_listener.TryGetTarget(out var target))
270 {
271 target.Unregister();
272 }
273 _listener = null;
274 }
275 }
276}
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static bool Equal(string strA, string strB)
Definition Ref.cs:5
bool IsMatch(XmlNode curNode)
override void PrivateDisposeNodeList()
WeakReference< XmlElementListListener > _listener
readonly string _asterisk
void Dispose(bool disposing)
override XmlNode Item(int index)
override IEnumerator GetEnumerator()
void ConcurrencyCheck(XmlNodeChangedEventArgs args)
XmlNode GetNthMatchingNode(XmlNode n, bool bNext, int nCount)
XmlNode GetMatchingNode(XmlNode n, bool bNext)
XmlElementList(XmlNode parent, string name)
XmlNode NextElemInPreOrder(XmlNode curNode)
XmlNode GetNextNode(XmlNode n)
readonly XmlNode _rootNode
XmlElementList(XmlNode parent, string localName, string namespaceURI)
XmlElementList(XmlNode parent)
XmlNode PrevElemInPreOrder(XmlNode curNode)
void IDisposable. Dispose()
virtual ? XmlNode PreviousSibling
Definition XmlNode.cs:102
XmlDocument Document
Definition XmlNode.cs:253
virtual ? XmlNode ParentNode
Definition XmlNode.cs:76
virtual ? XmlNode NextSibling
Definition XmlNode.cs:104
virtual string NamespaceURI
Definition XmlNode.cs:139
virtual ? XmlNode LastChild
Definition XmlNode.cs:122
virtual ? XmlNode FirstChild
Definition XmlNode.cs:120
XmlNodeType NodeType
Definition XmlNode.cs:73