Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlNamedNodeMap.cs
Go to the documentation of this file.
3
4namespace System.Xml;
5
7{
8 internal struct SmallXmlNodeList
9 {
10 private sealed class SingleObjectEnumerator : IEnumerator
11 {
12 private readonly object _loneValue;
13
14 private int _position = -1;
15
16 public object Current
17 {
18 get
19 {
20 if (_position != 0)
21 {
22 throw new InvalidOperationException();
23 }
24 return _loneValue;
25 }
26 }
27
29 {
31 }
32
33 public bool MoveNext()
34 {
35 if (_position < 0)
36 {
37 _position = 0;
38 return true;
39 }
40 _position = 1;
41 return false;
42 }
43
44 public void Reset()
45 {
46 _position = -1;
47 }
48 }
49
50 private object _field;
51
52 public int Count
53 {
54 get
55 {
56 if (_field == null)
57 {
58 return 0;
59 }
61 {
62 return list.Count;
63 }
64 return 1;
65 }
66 }
67
68 public object this[int index]
69 {
70 get
71 {
72 if (_field == null)
73 {
74 throw new ArgumentOutOfRangeException("index");
75 }
77 {
78 return list[index];
79 }
80 if (index != 0)
81 {
82 throw new ArgumentOutOfRangeException("index");
83 }
84 return _field;
85 }
86 }
87
88 public void Add(object value)
89 {
90 if (_field == null)
91 {
92 if (value == null)
93 {
95 list.Add(null);
96 _field = list;
97 }
98 else
99 {
100 _field = value;
101 }
102 }
103 else if (_field is List<object> list2)
104 {
105 list2.Add(value);
106 }
107 else
108 {
111 list3.Add(value);
112 _field = list3;
113 }
114 }
115
116 public void RemoveAt(int index)
117 {
118 if (_field == null)
119 {
120 throw new ArgumentOutOfRangeException("index");
121 }
123 {
124 list.RemoveAt(index);
125 return;
126 }
127 if (index != 0)
128 {
129 throw new ArgumentOutOfRangeException("index");
130 }
131 _field = null;
132 }
133
134 public void Insert(int index, object value)
135 {
136 if (_field == null)
137 {
138 if (index != 0)
139 {
140 throw new ArgumentOutOfRangeException("index");
141 }
142 Add(value);
143 return;
144 }
146 {
147 list.Insert(index, value);
148 return;
149 }
150 switch (index)
151 {
152 case 0:
153 {
155 list2.Add(value);
157 _field = list2;
158 break;
159 }
160 case 1:
161 {
164 list2.Add(value);
165 _field = list2;
166 break;
167 }
168 default:
169 throw new ArgumentOutOfRangeException("index");
170 }
171 }
172
174 {
175 if (_field == null)
176 {
178 }
180 {
181 return list.GetEnumerator();
182 }
183 return new SingleObjectEnumerator(_field);
184 }
185 }
186
187 internal XmlNode parent;
188
190
191 public virtual int Count => nodes.Count;
192
194 {
196 }
197
198 public virtual XmlNode? GetNamedItem(string name)
199 {
200 int num = FindNodeOffset(name);
201 if (num >= 0)
202 {
203 return (XmlNode)nodes[num];
204 }
205 return null;
206 }
207
209 {
210 if (node == null)
211 {
212 return null;
213 }
214 int num = FindNodeOffset(node.LocalName, node.NamespaceURI);
215 if (num == -1)
216 {
217 AddNode(node);
218 return null;
219 }
220 return ReplaceNodeAt(num, node);
221 }
222
223 public virtual XmlNode? RemoveNamedItem(string name)
224 {
225 int num = FindNodeOffset(name);
226 if (num >= 0)
227 {
228 return RemoveNodeAt(num);
229 }
230 return null;
231 }
232
233 public virtual XmlNode? Item(int index)
234 {
236 {
237 return null;
238 }
239 try
240 {
241 return (XmlNode)nodes[index];
242 }
244 {
246 }
247 }
248
249 public virtual XmlNode? GetNamedItem(string localName, string? namespaceURI)
250 {
251 int num = FindNodeOffset(localName, namespaceURI);
252 if (num >= 0)
253 {
254 return (XmlNode)nodes[num];
255 }
256 return null;
257 }
258
259 public virtual XmlNode? RemoveNamedItem(string localName, string? namespaceURI)
260 {
261 int num = FindNodeOffset(localName, namespaceURI);
262 if (num >= 0)
263 {
264 return RemoveNodeAt(num);
265 }
266 return null;
267 }
268
269 public virtual IEnumerator GetEnumerator()
270 {
271 return nodes.GetEnumerator();
272 }
273
274 internal int FindNodeOffset(string name)
275 {
276 int count = Count;
277 for (int i = 0; i < count; i++)
278 {
280 if (name == xmlNode.Name)
281 {
282 return i;
283 }
284 }
285 return -1;
286 }
287
288 internal int FindNodeOffset(string localName, string namespaceURI)
289 {
290 int count = Count;
291 for (int i = 0; i < count; i++)
292 {
294 if (xmlNode.LocalName == localName && xmlNode.NamespaceURI == namespaceURI)
295 {
296 return i;
297 }
298 }
299 return -1;
300 }
301
302 internal virtual XmlNode AddNode(XmlNode node)
303 {
304 XmlNode oldParent = ((node.NodeType != XmlNodeType.Attribute) ? node.ParentNode : ((XmlAttribute)node).OwnerElement);
305 string value = node.Value;
307 if (eventArgs != null)
308 {
310 }
311 nodes.Add(node);
312 node.SetParent(parent);
313 if (eventArgs != null)
314 {
316 }
317 return node;
318 }
319
321 {
322 XmlNodeChangedEventArgs insertEventArgsForLoad = doc.GetInsertEventArgsForLoad(node, parent);
323 if (insertEventArgsForLoad != null)
324 {
325 doc.BeforeEvent(insertEventArgsForLoad);
326 }
327 nodes.Add(node);
328 node.SetParent(parent);
329 if (insertEventArgsForLoad != null)
330 {
331 doc.AfterEvent(insertEventArgsForLoad);
332 }
333 return node;
334 }
335
336 internal virtual XmlNode RemoveNodeAt(int i)
337 {
339 string value = xmlNode.Value;
341 if (eventArgs != null)
342 {
344 }
345 nodes.RemoveAt(i);
346 xmlNode.SetParent(null);
347 if (eventArgs != null)
348 {
350 }
351 return xmlNode;
352 }
353
355 {
356 XmlNode result = RemoveNodeAt(i);
357 InsertNodeAt(i, node);
358 return result;
359 }
360
361 internal virtual XmlNode InsertNodeAt(int i, XmlNode node)
362 {
363 XmlNode oldParent = ((node.NodeType != XmlNodeType.Attribute) ? node.ParentNode : ((XmlAttribute)node).OwnerElement);
364 string value = node.Value;
366 if (eventArgs != null)
367 {
369 }
370 nodes.Insert(i, node);
371 node.SetParent(parent);
372 if (eventArgs != null)
373 {
375 }
376 return node;
377 }
378}
void Add(TKey key, TValue value)
static string Xdom_IndexOutOfRange
Definition SR.cs:1312
Definition SR.cs:7
static EmptyEnumerator EmptyEnumerator
virtual ? XmlNode RemoveNamedItem(string localName, string? namespaceURI)
virtual ? XmlNode RemoveNamedItem(string name)
virtual XmlNode AddNode(XmlNode node)
virtual IEnumerator GetEnumerator()
virtual XmlNode AddNodeForLoad(XmlNode node, XmlDocument doc)
XmlNode ReplaceNodeAt(int i, XmlNode node)
virtual ? XmlNode Item(int index)
int FindNodeOffset(string localName, string namespaceURI)
virtual ? XmlNode GetNamedItem(string name)
int FindNodeOffset(string name)
virtual XmlNode InsertNodeAt(int i, XmlNode node)
virtual ? XmlNode GetNamedItem(string localName, string? namespaceURI)
virtual ? XmlNode SetNamedItem(XmlNode? node)
virtual XmlNode RemoveNodeAt(int i)
virtual XmlNodeChangedEventArgs GetEventArgs(XmlNode node, XmlNode oldParent, XmlNode newParent, string oldValue, string newValue, XmlNodeChangedAction action)
Definition XmlNode.cs:1239
virtual void AfterEvent(XmlNodeChangedEventArgs args)
Definition XmlNode.cs:1261
virtual void BeforeEvent(XmlNodeChangedEventArgs args)
Definition XmlNode.cs:1253