Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XNode.cs
Go to the documentation of this file.
3using System.IO;
4using System.Text;
7
8namespace System.Xml.Linq;
9
10public abstract class XNode : XObject
11{
13
15
16 internal XNode next;
17
19 {
20 get
21 {
22 if (parent != null && this != parent.content)
23 {
24 return next;
25 }
26 return null;
27 }
28 }
29
31 {
32 get
33 {
34 if (parent == null)
35 {
36 return null;
37 }
38 XNode xNode = ((XNode)parent.content).next;
39 XNode result = null;
40 while (xNode != this)
41 {
42 result = xNode;
43 xNode = xNode.next;
44 }
45 return result;
46 }
47 }
48
50 {
51 get
52 {
53 if (s_documentOrderComparer == null)
54 {
56 }
58 }
59 }
60
62 {
63 get
64 {
65 if (s_equalityComparer == null)
66 {
68 }
69 return s_equalityComparer;
70 }
71 }
72
73 internal XNode()
74 {
75 }
76
77 public void AddAfterSelf(object? content)
78 {
79 if (parent == null)
80 {
82 }
83 new Inserter(parent, this).Add(content);
84 }
85
86 public void AddAfterSelf(params object?[] content)
87 {
88 AddAfterSelf((object?)content);
89 }
90
91 public void AddBeforeSelf(object? content)
92 {
93 if (parent == null)
94 {
96 }
98 while (xNode.next != this)
99 {
100 xNode = xNode.next;
101 }
102 if (xNode == parent.content)
103 {
104 xNode = null;
105 }
106 new Inserter(parent, xNode).Add(content);
107 }
108
109 public void AddBeforeSelf(params object?[] content)
110 {
111 AddBeforeSelf((object?)content);
112 }
113
115 {
116 return GetAncestors(null, self: false);
117 }
118
120 {
121 if (!(name != null))
122 {
123 return XElement.EmptySequence;
124 }
125 return GetAncestors(name, self: false);
126 }
127
128 public static int CompareDocumentOrder(XNode? n1, XNode? n2)
129 {
130 if (n1 == n2)
131 {
132 return 0;
133 }
134 if (n1 == null)
135 {
136 return -1;
137 }
138 if (n2 == null)
139 {
140 return 1;
141 }
142 if (n1.parent != n2.parent)
143 {
144 int num = 0;
145 XNode xNode = n1;
146 while (xNode.parent != null)
147 {
148 xNode = xNode.parent;
149 num++;
150 }
151 XNode xNode2 = n2;
152 while (xNode2.parent != null)
153 {
154 xNode2 = xNode2.parent;
155 num--;
156 }
157 if (xNode != xNode2)
158 {
160 }
161 if (num < 0)
162 {
163 do
164 {
165 n2 = n2.parent;
166 num++;
167 }
168 while (num != 0);
169 if (n1 == n2)
170 {
171 return -1;
172 }
173 }
174 else if (num > 0)
175 {
176 do
177 {
178 n1 = n1.parent;
179 num--;
180 }
181 while (num != 0);
182 if (n1 == n2)
183 {
184 return 1;
185 }
186 }
187 while (n1.parent != n2.parent)
188 {
189 n1 = n1.parent;
190 n2 = n2.parent;
191 }
192 }
193 else if (n1.parent == null)
194 {
196 }
197 XNode xNode3 = (XNode)n1.parent.content;
198 do
199 {
200 xNode3 = xNode3.next;
201 if (xNode3 == n1)
202 {
203 return -1;
204 }
205 }
206 while (xNode3 != n2);
207 return 1;
208 }
209
211 {
212 return new XNodeReader(this, null);
213 }
214
216 {
217 return new XNodeReader(this, null, readerOptions);
218 }
219
221 {
222 XNode i = this;
223 while (i.parent != null && i != i.parent.content)
224 {
225 i = i.next;
226 yield return i;
227 }
228 }
229
231 {
232 if (parent == null)
233 {
234 yield break;
235 }
237 do
238 {
239 i = i.next;
240 if (i != this)
241 {
242 yield return i;
243 continue;
244 }
245 break;
246 }
247 while (parent != null && parent == i.parent);
248 }
249
251 {
252 return GetElementsAfterSelf(null);
253 }
254
256 {
257 if (!(name != null))
258 {
259 return XElement.EmptySequence;
260 }
261 return GetElementsAfterSelf(name);
262 }
263
265 {
266 return GetElementsBeforeSelf(null);
267 }
268
270 {
271 if (!(name != null))
272 {
273 return XElement.EmptySequence;
274 }
275 return GetElementsBeforeSelf(name);
276 }
277
278 public bool IsAfter(XNode? node)
279 {
280 return CompareDocumentOrder(this, node) > 0;
281 }
282
283 public bool IsBefore(XNode? node)
284 {
285 return CompareDocumentOrder(this, node) < 0;
286 }
287
288 public static XNode ReadFrom(XmlReader reader)
289 {
290 if (reader == null)
291 {
292 throw new ArgumentNullException("reader");
293 }
294 if (reader.ReadState != ReadState.Interactive)
295 {
297 }
298 switch (reader.NodeType)
299 {
300 case XmlNodeType.Text:
301 case XmlNodeType.Whitespace:
302 case XmlNodeType.SignificantWhitespace:
303 return new XText(reader);
304 case XmlNodeType.CDATA:
305 return new XCData(reader);
306 case XmlNodeType.Comment:
307 return new XComment(reader);
308 case XmlNodeType.DocumentType:
309 return new XDocumentType(reader);
310 case XmlNodeType.Element:
311 return new XElement(reader);
312 case XmlNodeType.ProcessingInstruction:
313 return new XProcessingInstruction(reader);
314 default:
316 }
317 }
318
320 {
321 if (reader == null)
322 {
323 throw new ArgumentNullException("reader");
324 }
325 if (cancellationToken.IsCancellationRequested)
326 {
328 }
330 }
331
333 {
334 if (reader.ReadState != ReadState.Interactive)
335 {
337 }
338 XNode ret;
339 switch (reader.NodeType)
340 {
341 case XmlNodeType.Text:
342 case XmlNodeType.Whitespace:
343 case XmlNodeType.SignificantWhitespace:
344 ret = new XText(reader.Value);
345 break;
346 case XmlNodeType.CDATA:
347 ret = new XCData(reader.Value);
348 break;
349 case XmlNodeType.Comment:
350 ret = new XComment(reader.Value);
351 break;
352 case XmlNodeType.DocumentType:
353 {
354 string name2 = reader.Name;
355 string attribute = reader.GetAttribute("PUBLIC");
356 string attribute2 = reader.GetAttribute("SYSTEM");
357 string value2 = reader.Value;
359 break;
360 }
361 case XmlNodeType.Element:
362 return await XElement.CreateAsync(reader, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
363 case XmlNodeType.ProcessingInstruction:
364 {
365 string name = reader.Name;
366 string value = reader.Value;
367 ret = new XProcessingInstruction(name, value);
368 break;
369 }
370 default:
372 }
373 cancellationToken.ThrowIfCancellationRequested();
374 await reader.ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
375 return ret;
376 }
377
378 public void Remove()
379 {
380 if (parent == null)
381 {
383 }
384 parent.RemoveNode(this);
385 }
386
387 public void ReplaceWith(object? content)
388 {
389 if (parent == null)
390 {
392 }
395 while (xNode.next != this)
396 {
397 xNode = xNode.next;
398 }
399 if (xNode == parent.content)
400 {
401 xNode = null;
402 }
403 parent.RemoveNode(this);
404 if (xNode != null && xNode.parent != xContainer)
405 {
407 }
408 new Inserter(xContainer, xNode).Add(content);
409 }
410
411 public void ReplaceWith(params object?[] content)
412 {
413 ReplaceWith((object?)content);
414 }
415
416 public override string ToString()
417 {
419 }
420
422 {
423 return GetXmlString(options);
424 }
425
426 public static bool DeepEquals(XNode? n1, XNode? n2)
427 {
428 if (n1 == n2)
429 {
430 return true;
431 }
432 if (n1 == null || n2 == null)
433 {
434 return false;
435 }
436 return n1.DeepEquals(n2);
437 }
438
439 public abstract void WriteTo(XmlWriter writer);
440
442
443 internal virtual void AppendText(StringBuilder sb)
444 {
445 }
446
447 internal abstract XNode CloneNode();
448
449 internal abstract bool DeepEquals(XNode node);
450
451 internal IEnumerable<XElement> GetAncestors(XName name, bool self)
452 {
453 for (XElement e = (self ? this : parent) as XElement; e != null; e = e.parent as XElement)
454 {
455 if (name == null || e.name == name)
456 {
457 yield return e;
458 }
459 }
460 }
461
463 {
464 XNode i = this;
465 while (i.parent != null && i != i.parent.content)
466 {
467 i = i.next;
468 if (i is XElement xElement && (name == null || xElement.name == name))
469 {
470 yield return xElement;
471 }
472 }
473 }
474
476 {
477 if (parent == null)
478 {
479 yield break;
480 }
482 do
483 {
484 i = i.next;
485 if (i != this)
486 {
487 if (i is XElement xElement && (name == null || xElement.name == name))
488 {
489 yield return xElement;
490 }
491 continue;
492 }
493 break;
494 }
495 while (parent != null && parent == i.parent);
496 }
497
498 internal abstract int GetDeepHashCode();
499
511
513 {
515 if ((o & SaveOptions.DisableFormatting) == 0)
516 {
518 }
519 if ((o & SaveOptions.OmitDuplicateNamespaces) != 0)
520 {
522 }
523 return xmlWriterSettings;
524 }
525
526 private string GetXmlString(SaveOptions o)
527 {
531 if ((o & SaveOptions.DisableFormatting) == 0)
532 {
534 }
535 if ((o & SaveOptions.OmitDuplicateNamespaces) != 0)
536 {
538 }
539 if (this is XText)
540 {
542 }
544 {
545 if (this is XDocument xDocument)
546 {
547 xDocument.WriteContentTo(writer);
548 }
549 else
550 {
552 }
553 }
554 return stringWriter.ToString();
555 }
556}
static CultureInfo InvariantCulture
static string InvalidOperation_MissingParent
Definition SR.cs:54
static string InvalidOperation_ExternalCode
Definition SR.cs:50
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InvalidOperation_ExpectedInteractive
Definition SR.cs:46
static string InvalidOperation_MissingAncestor
Definition SR.cs:52
static string InvalidOperation_UnexpectedNodeType
Definition SR.cs:58
Definition SR.cs:7
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363
static IEnumerable< XElement > EmptySequence
Definition XElement.cs:29
static async Task< XElement > CreateAsync(XmlReader r, CancellationToken cancellationToken)
Definition XElement.cs:185
static XmlWriterSettings GetXmlWriterSettings(SaveOptions o)
Definition XNode.cs:512
XmlReader CreateReader()
Definition XNode.cs:210
bool DeepEquals(XNode node)
IEnumerable< XElement > ElementsBeforeSelf(XName? name)
Definition XNode.cs:269
IEnumerable< XElement > ElementsAfterSelf()
Definition XNode.cs:250
IEnumerable< XElement > GetAncestors(XName name, bool self)
Definition XNode.cs:451
IEnumerable< XElement > Ancestors()
Definition XNode.cs:114
override string ToString()
Definition XNode.cs:416
static bool DeepEquals(XNode? n1, XNode? n2)
Definition XNode.cs:426
static Task< XNode > ReadFromAsync(XmlReader reader, CancellationToken cancellationToken)
Definition XNode.cs:319
IEnumerable< XElement > ElementsAfterSelf(XName? name)
Definition XNode.cs:255
void AddAfterSelf(params object?[] content)
Definition XNode.cs:86
static XNodeEqualityComparer s_equalityComparer
Definition XNode.cs:14
Task WriteToAsync(XmlWriter writer, CancellationToken cancellationToken)
IEnumerable< XElement > GetElementsBeforeSelf(XName name)
Definition XNode.cs:475
IEnumerable< XElement > GetElementsAfterSelf(XName name)
Definition XNode.cs:462
static XNode ReadFrom(XmlReader reader)
Definition XNode.cs:288
IEnumerable< XElement > ElementsBeforeSelf()
Definition XNode.cs:264
static XNodeDocumentOrderComparer DocumentOrderComparer
Definition XNode.cs:50
void WriteTo(XmlWriter writer)
string GetXmlString(SaveOptions o)
Definition XNode.cs:526
void AddAfterSelf(object? content)
Definition XNode.cs:77
bool IsBefore(XNode? node)
Definition XNode.cs:283
virtual void AppendText(StringBuilder sb)
Definition XNode.cs:443
string ToString(SaveOptions options)
Definition XNode.cs:421
static XmlReaderSettings GetXmlReaderSettings(LoadOptions o)
Definition XNode.cs:500
bool IsAfter(XNode? node)
Definition XNode.cs:278
static async Task< XNode > ReadFromAsyncInternal(XmlReader reader, CancellationToken cancellationToken)
Definition XNode.cs:332
void AddBeforeSelf(params object?[] content)
Definition XNode.cs:109
XmlReader CreateReader(ReaderOptions readerOptions)
Definition XNode.cs:215
IEnumerable< XNode > NodesAfterSelf()
Definition XNode.cs:220
XNode? PreviousNode
Definition XNode.cs:31
void ReplaceWith(object? content)
Definition XNode.cs:387
static XNodeDocumentOrderComparer s_documentOrderComparer
Definition XNode.cs:12
static int CompareDocumentOrder(XNode? n1, XNode? n2)
Definition XNode.cs:128
IEnumerable< XNode > NodesBeforeSelf()
Definition XNode.cs:230
void ReplaceWith(params object?[] content)
Definition XNode.cs:411
IEnumerable< XElement > Ancestors(XName? name)
Definition XNode.cs:119
void AddBeforeSelf(object? content)
Definition XNode.cs:91
XContainer parent
Definition XObject.cs:7
SaveOptions GetSaveOptionsFromAnnotations()
Definition XObject.cs:490
string? GetAttribute(string name)
virtual Task< bool > ReadAsync()
XmlNodeType NodeType
Definition XmlReader.cs:62
virtual string Name
Definition XmlReader.cs:65
static XmlWriter Create(string outputFileName)
Definition XmlWriter.cs:468
void Add(object content)
Definition Inserter.cs:20