Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XContainer.cs
Go to the documentation of this file.
4using System.Text;
7
8namespace System.Xml.Linq;
9
10public abstract class XContainer : XNode
11{
12 private sealed class ContentReader
13 {
14 private readonly NamespaceCache _eCache;
15
16 private readonly NamespaceCache _aCache;
17
18 private readonly IXmlLineInfo _lineInfo;
19
21
22 private string _baseUri;
23
28
30 {
32 _baseUri = (((o & LoadOptions.SetBaseUri) != 0) ? r.BaseURI : null);
33 _lineInfo = (((o & LoadOptions.SetLineInfo) != 0) ? (r as IXmlLineInfo) : null);
34 }
35
37 {
38 switch (r.NodeType)
39 {
40 case XmlNodeType.Element:
41 {
42 XElement xElement = new XElement(_eCache.Get(r.NamespaceURI).GetName(r.LocalName));
43 if (r.MoveToFirstAttribute())
44 {
45 do
46 {
47 xElement.AppendAttributeSkipNotify(new XAttribute(_aCache.Get((r.Prefix.Length == 0) ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value));
48 }
49 while (r.MoveToNextAttribute());
50 r.MoveToElement();
51 }
53 if (!r.IsEmptyElement)
54 {
56 }
57 break;
58 }
59 case XmlNodeType.EndElement:
60 if (_currentContainer.content == null)
61 {
62 _currentContainer.content = string.Empty;
63 }
65 {
66 return false;
67 }
69 break;
70 case XmlNodeType.Text:
71 case XmlNodeType.Whitespace:
72 case XmlNodeType.SignificantWhitespace:
74 break;
75 case XmlNodeType.CDATA:
77 break;
78 case XmlNodeType.Comment:
80 break;
81 case XmlNodeType.ProcessingInstruction:
83 break;
84 case XmlNodeType.DocumentType:
85 _currentContainer.AddNodeSkipNotify(new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value));
86 break;
87 case XmlNodeType.EntityReference:
88 if (!r.CanResolveEntity)
89 {
91 }
92 r.ResolveEntity();
93 break;
94 default:
96 case XmlNodeType.EndEntity:
97 break;
98 }
99 return true;
100 }
101
103 {
104 switch (r.NodeType)
105 {
106 case XmlNodeType.Element:
107 {
108 XElement e = new XElement(_eCache.Get(r.NamespaceURI).GetName(r.LocalName));
109 if (r.MoveToFirstAttribute())
110 {
111 do
112 {
113 XElement xElement = e;
114 XName name = _aCache.Get((r.Prefix.Length == 0) ? string.Empty : r.NamespaceURI).GetName(r.LocalName);
115 xElement.AppendAttributeSkipNotify(new XAttribute(name, await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false)));
116 }
117 while (r.MoveToNextAttribute());
118 r.MoveToElement();
119 }
121 if (!r.IsEmptyElement)
122 {
124 }
125 break;
126 }
127 case XmlNodeType.EndElement:
128 if (_currentContainer.content == null)
129 {
130 _currentContainer.content = string.Empty;
131 }
133 {
134 return false;
135 }
137 break;
138 case XmlNodeType.Text:
139 case XmlNodeType.Whitespace:
140 case XmlNodeType.SignificantWhitespace:
141 {
143 currentContainer.AddStringSkipNotify(await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false));
144 break;
145 }
146 case XmlNodeType.CDATA:
147 {
149 currentContainer.AddNodeSkipNotify(new XCData(await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false)));
150 break;
151 }
152 case XmlNodeType.Comment:
153 {
155 currentContainer.AddNodeSkipNotify(new XComment(await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false)));
156 break;
157 }
158 case XmlNodeType.ProcessingInstruction:
159 {
161 string localName = r.Name;
162 currentContainer.AddNodeSkipNotify(new XProcessingInstruction(localName, await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false)));
163 break;
164 }
165 case XmlNodeType.DocumentType:
166 {
168 string localName = r.LocalName;
169 string attribute = r.GetAttribute("PUBLIC");
170 string attribute2 = r.GetAttribute("SYSTEM");
171 currentContainer.AddNodeSkipNotify(new XDocumentType(localName, attribute, attribute2, await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false)));
172 break;
173 }
174 case XmlNodeType.EntityReference:
175 if (!r.CanResolveEntity)
176 {
178 }
179 r.ResolveEntity();
180 break;
181 default:
183 case XmlNodeType.EndEntity:
184 break;
185 }
186 return true;
187 }
188
190 {
191 XNode xNode = null;
192 string baseURI = r.BaseURI;
193 switch (r.NodeType)
194 {
195 case XmlNodeType.Element:
196 {
197 XElement xElement2 = new XElement(_eCache.Get(r.NamespaceURI).GetName(r.LocalName));
198 if (_baseUri != null && _baseUri != baseURI)
199 {
200 xElement2.SetBaseUri(baseURI);
201 }
202 if (_lineInfo != null && _lineInfo.HasLineInfo())
203 {
205 }
206 if (r.MoveToFirstAttribute())
207 {
208 do
209 {
210 XAttribute xAttribute = new XAttribute(_aCache.Get((r.Prefix.Length == 0) ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value);
211 if (_lineInfo != null && _lineInfo.HasLineInfo())
212 {
214 }
215 xElement2.AppendAttributeSkipNotify(xAttribute);
216 }
217 while (r.MoveToNextAttribute());
218 r.MoveToElement();
219 }
221 if (!r.IsEmptyElement)
222 {
224 if (_baseUri != null)
225 {
226 _baseUri = baseURI;
227 }
228 }
229 break;
230 }
231 case XmlNodeType.EndElement:
232 if (_currentContainer.content == null)
233 {
234 _currentContainer.content = string.Empty;
235 }
237 {
238 xElement.SetEndElementLineInfo(_lineInfo.LineNumber, _lineInfo.LinePosition);
239 }
241 {
242 return false;
243 }
245 {
247 }
249 break;
250 case XmlNodeType.Text:
251 case XmlNodeType.Whitespace:
252 case XmlNodeType.SignificantWhitespace:
253 if ((_baseUri != null && _baseUri != baseURI) || (_lineInfo != null && _lineInfo.HasLineInfo()))
254 {
255 xNode = new XText(r.Value);
256 }
257 else
258 {
260 }
261 break;
262 case XmlNodeType.CDATA:
263 xNode = new XCData(r.Value);
264 break;
265 case XmlNodeType.Comment:
266 xNode = new XComment(r.Value);
267 break;
268 case XmlNodeType.ProcessingInstruction:
269 xNode = new XProcessingInstruction(r.Name, r.Value);
270 break;
271 case XmlNodeType.DocumentType:
272 xNode = new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value);
273 break;
274 case XmlNodeType.EntityReference:
275 if (!r.CanResolveEntity)
276 {
278 }
279 r.ResolveEntity();
280 break;
281 default:
283 case XmlNodeType.EndEntity:
284 break;
285 }
286 if (xNode != null)
287 {
288 if (_baseUri != null && _baseUri != baseURI)
289 {
290 xNode.SetBaseUri(baseURI);
291 }
292 if (_lineInfo != null && _lineInfo.HasLineInfo())
293 {
295 }
297 xNode = null;
298 }
299 return true;
300 }
301
303 {
304 XNode newNode = null;
305 string baseUri = r.BaseURI;
306 switch (r.NodeType)
307 {
308 case XmlNodeType.Element:
309 {
310 XElement e = new XElement(_eCache.Get(r.NamespaceURI).GetName(r.LocalName));
311 if (_baseUri != null && _baseUri != baseUri)
312 {
313 e.SetBaseUri(baseUri);
314 }
315 if (_lineInfo != null && _lineInfo.HasLineInfo())
316 {
318 }
319 if (r.MoveToFirstAttribute())
320 {
321 do
322 {
323 XName name = _aCache.Get((r.Prefix.Length == 0) ? string.Empty : r.NamespaceURI).GetName(r.LocalName);
324 XAttribute xAttribute = new XAttribute(name, await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false));
325 if (_lineInfo != null && _lineInfo.HasLineInfo())
326 {
328 }
330 }
331 while (r.MoveToNextAttribute());
332 r.MoveToElement();
333 }
335 if (!r.IsEmptyElement)
336 {
338 if (_baseUri != null)
339 {
340 _baseUri = baseUri;
341 }
342 }
343 break;
344 }
345 case XmlNodeType.EndElement:
346 if (_currentContainer.content == null)
347 {
348 _currentContainer.content = string.Empty;
349 }
351 {
352 xElement.SetEndElementLineInfo(_lineInfo.LineNumber, _lineInfo.LinePosition);
353 }
355 {
356 return false;
357 }
359 {
361 }
363 break;
364 case XmlNodeType.Text:
365 case XmlNodeType.Whitespace:
366 case XmlNodeType.SignificantWhitespace:
367 {
368 if ((_baseUri != null && _baseUri != baseUri) || (_lineInfo != null && _lineInfo.HasLineInfo()))
369 {
370 newNode = new XText(await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false));
371 break;
372 }
374 currentContainer.AddStringSkipNotify(await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false));
375 break;
376 }
377 case XmlNodeType.CDATA:
378 newNode = new XCData(await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false));
379 break;
380 case XmlNodeType.Comment:
381 newNode = new XComment(await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false));
382 break;
383 case XmlNodeType.ProcessingInstruction:
384 {
385 string localName = r.Name;
386 newNode = new XProcessingInstruction(localName, await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false));
387 break;
388 }
389 case XmlNodeType.DocumentType:
390 {
391 string localName = r.LocalName;
392 string attribute = r.GetAttribute("PUBLIC");
393 string attribute2 = r.GetAttribute("SYSTEM");
394 newNode = new XDocumentType(localName, attribute, attribute2, await r.GetValueAsync().ConfigureAwait(continueOnCapturedContext: false));
395 break;
396 }
397 case XmlNodeType.EntityReference:
398 if (!r.CanResolveEntity)
399 {
401 }
402 r.ResolveEntity();
403 break;
404 default:
406 case XmlNodeType.EndEntity:
407 break;
408 }
409 if (newNode != null)
410 {
411 if (_baseUri != null && _baseUri != baseUri)
412 {
413 newNode.SetBaseUri(baseUri);
414 }
415 if (_lineInfo != null && _lineInfo.HasLineInfo())
416 {
418 }
420 }
421 return true;
422 }
423 }
424
425 internal object content;
426
428
430 {
431 get
432 {
433 if (content == null)
434 {
435 return null;
436 }
437 if (content is XNode result)
438 {
439 return result;
440 }
441 if (content is string text)
442 {
443 if (text.Length == 0)
444 {
445 return null;
446 }
447 XText xText = new XText(text);
448 xText.parent = this;
450 Interlocked.CompareExchange<object>(ref content, (object)xText, (object)text);
451 }
452 return (XNode)content;
453 }
454 }
455
456 internal XContainer()
457 {
458 }
459
461 {
462 if (other == null)
463 {
464 throw new ArgumentNullException("other");
465 }
466 if (other.content is string)
467 {
468 content = other.content;
469 return;
470 }
471 XNode xNode = (XNode)other.content;
472 if (xNode != null)
473 {
474 do
475 {
476 xNode = xNode.next;
477 AppendNodeSkipNotify(xNode.CloneNode());
478 }
479 while (xNode != other.content);
480 }
481 }
482
483 public void Add(object? content)
484 {
485 if (SkipNotify())
486 {
488 }
489 else
490 {
491 if (content == null)
492 {
493 return;
494 }
495 if (content is XNode n)
496 {
497 AddNode(n);
498 return;
499 }
500 if (content is string s)
501 {
502 AddString(s);
503 return;
504 }
506 {
508 return;
509 }
511 {
512 AddNode(new XElement(other));
513 return;
514 }
515 if (content is object[] array)
516 {
517 object[] array2 = array;
518 foreach (object obj in array2)
519 {
520 Add(obj);
521 }
522 return;
523 }
524 if (content is IEnumerable enumerable)
525 {
526 {
527 foreach (object item in enumerable)
528 {
529 Add(item);
530 }
531 return;
532 }
533 }
535 }
536 }
537
538 public void Add(params object?[] content)
539 {
540 Add((object?)content);
541 }
542
543 public void AddFirst(object? content)
544 {
545 new Inserter(this, null).Add(content);
546 }
547
548 public void AddFirst(params object?[] content)
549 {
550 AddFirst((object?)content);
551 }
552
559
561 {
562 return GetDescendantNodes(self: false);
563 }
564
566 {
567 return GetDescendants(null, self: false);
568 }
569
571 {
572 if (!(name != null))
573 {
574 return XElement.EmptySequence;
575 }
576 return GetDescendants(name, self: false);
577 }
578
579 public XElement? Element(XName name)
580 {
582 if (xNode != null)
583 {
584 do
585 {
586 xNode = xNode.next;
587 if (xNode is XElement xElement && xElement.name == name)
588 {
589 return xElement;
590 }
591 }
592 while (xNode != content);
593 }
594 return null;
595 }
596
598 {
599 return GetElements(null);
600 }
601
603 {
604 if (!(name != null))
605 {
606 return XElement.EmptySequence;
607 }
608 return GetElements(name);
609 }
610
612 {
613 XNode i = LastNode;
614 if (i != null)
615 {
616 do
617 {
618 i = i.next;
619 yield return i;
620 }
621 while (i.parent == this && i != content);
622 }
623 }
624
625 public void RemoveNodes()
626 {
627 if (SkipNotify())
628 {
630 return;
631 }
632 while (content != null)
633 {
634 if (content is string text)
635 {
636 if (text.Length > 0)
637 {
639 }
640 else if (this is XElement)
641 {
643 if (text != content)
644 {
646 }
647 content = null;
649 }
650 else
651 {
652 content = null;
653 }
654 }
656 {
658 if (xNode != content || xNode2 != xNode.next)
659 {
661 }
662 if (xNode2 != xNode)
663 {
664 xNode.next = xNode2.next;
665 }
666 else
667 {
668 content = null;
669 }
670 xNode2.parent = null;
671 xNode2.next = null;
673 }
674 }
675 }
676
677 public void ReplaceNodes(object? content)
678 {
680 RemoveNodes();
681 Add(content);
682 }
683
684 public void ReplaceNodes(params object?[] content)
685 {
686 ReplaceNodes((object?)content);
687 }
688
689 internal virtual void AddAttribute(XAttribute a)
690 {
691 }
692
693 internal virtual void AddAttributeSkipNotify(XAttribute a)
694 {
695 }
696
697 internal void AddContentSkipNotify(object content)
698 {
699 if (content == null)
700 {
701 return;
702 }
703 if (content is XNode n)
704 {
706 return;
707 }
708 if (content is string s)
709 {
711 return;
712 }
714 {
716 return;
717 }
719 {
721 return;
722 }
723 if (content is object[] array)
724 {
725 object[] array2 = array;
726 foreach (object obj in array2)
727 {
729 }
730 return;
731 }
732 if (content is IEnumerable enumerable)
733 {
734 {
735 foreach (object item in enumerable)
736 {
738 }
739 return;
740 }
741 }
743 }
744
745 internal void AddNode(XNode n)
746 {
747 ValidateNode(n, this);
748 if (n.parent != null)
749 {
750 n = n.CloneNode();
751 }
752 else
753 {
754 XNode xNode = this;
755 while (xNode.parent != null)
756 {
757 xNode = xNode.parent;
758 }
759 if (n == xNode)
760 {
761 n = n.CloneNode();
762 }
763 }
765 AppendNode(n);
766 }
767
768 internal void AddNodeSkipNotify(XNode n)
769 {
770 ValidateNode(n, this);
771 if (n.parent != null)
772 {
773 n = n.CloneNode();
774 }
775 else
776 {
777 XNode xNode = this;
778 while (xNode.parent != null)
779 {
780 xNode = xNode.parent;
781 }
782 if (n == xNode)
783 {
784 n = n.CloneNode();
785 }
786 }
789 }
790
791 internal void AddString(string s)
792 {
794 if (content == null)
795 {
796 if (s.Length > 0)
797 {
798 AppendNode(new XText(s));
799 }
800 else if (this is XElement)
801 {
803 if (content != null)
804 {
806 }
807 content = s;
809 }
810 else
811 {
812 content = s;
813 }
814 }
815 else if (s.Length > 0)
816 {
818 if (content is XText xText && !(xText is XCData))
819 {
820 xText.Value += s;
821 }
822 else
823 {
824 AppendNode(new XText(s));
825 }
826 }
827 }
828
829 internal void AddStringSkipNotify(string s)
830 {
832 if (content == null)
833 {
834 content = s;
835 }
836 else if (s.Length > 0)
837 {
838 if (content is string text)
839 {
840 content = text + s;
841 }
842 else if (content is XText xText && !(xText is XCData))
843 {
844 xText.text += s;
845 }
846 else
847 {
849 }
850 }
851 }
852
853 internal void AppendNode(XNode n)
854 {
856 if (n.parent != null)
857 {
859 }
861 if (flag)
862 {
864 }
865 }
866
868 {
869 n.parent = this;
870 if (content == null || content is string)
871 {
872 n.next = n;
873 }
874 else
875 {
877 n.next = xNode.next;
878 xNode.next = n;
879 }
880 content = n;
881 }
882
883 internal override void AppendText(StringBuilder sb)
884 {
885 if (content is string value)
886 {
887 sb.Append(value);
888 return;
889 }
891 if (xNode != null)
892 {
893 do
894 {
895 xNode = xNode.next;
896 xNode.AppendText(sb);
897 }
898 while (xNode != content);
899 }
900 }
901
902 private string GetTextOnly()
903 {
904 if (content == null)
905 {
906 return null;
907 }
908 string text = content as string;
909 if (text == null)
910 {
912 do
913 {
914 xNode = xNode.next;
915 if (xNode.NodeType != XmlNodeType.Text)
916 {
917 return null;
918 }
919 text += ((XText)xNode).Value;
920 }
921 while (xNode != content);
922 }
923 return text;
924 }
925
926 private string CollectText(ref XNode n)
927 {
928 string text = "";
929 while (n != null && n.NodeType == XmlNodeType.Text)
930 {
931 text += ((XText)n).Value;
932 n = ((n != content) ? n.next : null);
933 }
934 return text;
935 }
936
937 internal bool ContentsEqual(XContainer e)
938 {
939 if (content == e.content)
940 {
941 return true;
942 }
943 string textOnly = GetTextOnly();
944 if (textOnly != null)
945 {
946 return textOnly == e.GetTextOnly();
947 }
950 if (xNode != null && xNode2 != null)
951 {
952 xNode = xNode.next;
953 xNode2 = xNode2.next;
954 while (!(CollectText(ref xNode) != e.CollectText(ref xNode2)))
955 {
956 if (xNode == null && xNode2 == null)
957 {
958 return true;
959 }
960 if (xNode == null || xNode2 == null || !xNode.DeepEquals(xNode2))
961 {
962 break;
963 }
964 xNode = ((xNode != content) ? xNode.next : null);
965 xNode2 = ((xNode2 != e.content) ? xNode2.next : null);
966 }
967 }
968 return false;
969 }
970
971 internal int ContentsHashCode()
972 {
973 string textOnly = GetTextOnly();
974 if (textOnly != null)
975 {
976 return textOnly.GetHashCode();
977 }
978 int num = 0;
980 if (n != null)
981 {
982 do
983 {
984 n = n.next;
985 string text = CollectText(ref n);
986 if (text.Length > 0)
987 {
988 num ^= text.GetHashCode();
989 }
990 if (n == null)
991 {
992 break;
993 }
994 num ^= n.GetDeepHashCode();
995 }
996 while (n != content);
997 }
998 return num;
999 }
1000
1001 internal void ConvertTextToNode()
1002 {
1003 string value = content as string;
1004 if (!string.IsNullOrEmpty(value))
1005 {
1006 XText xText = new XText(value);
1007 xText.parent = this;
1008 xText.next = xText;
1009 content = xText;
1010 }
1011 }
1012
1014 {
1015 if (self)
1016 {
1017 yield return this;
1018 }
1019 XNode i = this;
1020 while (true)
1021 {
1023 if (i is XContainer xContainer && (firstNode = xContainer.FirstNode) != null)
1024 {
1025 i = firstNode;
1026 }
1027 else
1028 {
1029 while (i != null && i != this && i == i.parent.content)
1030 {
1031 i = i.parent;
1032 }
1033 if (i == null || i == this)
1034 {
1035 break;
1036 }
1037 i = i.next;
1038 }
1039 yield return i;
1040 }
1041 }
1042
1044 {
1045 if (self)
1046 {
1047 XElement xElement = (XElement)this;
1048 if (name == null || xElement.name == name)
1049 {
1050 yield return xElement;
1051 }
1052 }
1053 XNode i = this;
1054 XContainer xContainer = this;
1055 while (true)
1056 {
1057 if (xContainer != null && xContainer.content is XNode)
1058 {
1059 i = ((XNode)xContainer.content).next;
1060 }
1061 else
1062 {
1063 while (i != this && i == i.parent.content)
1064 {
1065 i = i.parent;
1066 }
1067 if (i == this)
1068 {
1069 break;
1070 }
1071 i = i.next;
1072 }
1073 XElement e = i as XElement;
1074 if (e != null && (name == null || e.name == name))
1075 {
1076 yield return e;
1077 }
1078 xContainer = e;
1079 }
1080 }
1081
1083 {
1084 XNode i = content as XNode;
1085 if (i == null)
1086 {
1087 yield break;
1088 }
1089 do
1090 {
1091 i = i.next;
1092 if (i is XElement xElement && (name == null || xElement.name == name))
1093 {
1094 yield return xElement;
1095 }
1096 }
1097 while (i.parent == this && i != content);
1098 }
1099
1100 internal static string GetStringValue(object value)
1101 {
1102 string text2;
1103 if (!(value is string text))
1104 {
1105 if (!(value is int num))
1106 {
1107 if (!(value is double num2))
1108 {
1109 if (!(value is long num3))
1110 {
1111 if (!(value is float num4))
1112 {
1113 if (!(value is decimal num5))
1114 {
1115 if (!(value is short num6))
1116 {
1117 if (!(value is sbyte b))
1118 {
1119 if (!(value is bool flag))
1120 {
1121 if (!(value is DateTime dateTime))
1122 {
1124 {
1125 if (!(value is TimeSpan timeSpan))
1126 {
1127 if (value is XObject)
1128 {
1130 }
1131 text2 = value.ToString();
1132 }
1133 else
1134 {
1136 }
1137 }
1138 else
1139 {
1141 }
1142 }
1143 else
1144 {
1146 }
1147 }
1148 else
1149 {
1150 text2 = XmlConvert.ToString(flag);
1151 }
1152 }
1153 else
1154 {
1156 }
1157 }
1158 else
1159 {
1161 }
1162 }
1163 else
1164 {
1166 }
1167 }
1168 else
1169 {
1171 }
1172 }
1173 else
1174 {
1176 }
1177 }
1178 else
1179 {
1181 }
1182 }
1183 else
1184 {
1185 text2 = XmlConvert.ToString(num);
1186 }
1187 }
1188 else
1189 {
1190 text2 = text;
1191 }
1192 string text3 = text2;
1193 if (text3 == null)
1194 {
1196 }
1197 return text3;
1198 }
1199
1201 {
1202 if (r.ReadState != ReadState.Interactive)
1203 {
1205 }
1207 while (contentReader.ReadContentFrom(this, r) && r.Read())
1208 {
1209 }
1210 }
1211
1213 {
1214 if ((o & (LoadOptions.SetBaseUri | LoadOptions.SetLineInfo)) == 0)
1215 {
1217 return;
1218 }
1219 if (r.ReadState != ReadState.Interactive)
1220 {
1222 }
1224 while (contentReader.ReadContentFrom(this, r, o) && r.Read())
1225 {
1226 }
1227 }
1228
1230 {
1231 if (r.ReadState != ReadState.Interactive)
1232 {
1234 }
1235 ContentReader cr = new ContentReader(this);
1236 bool flag;
1237 do
1238 {
1239 cancellationToken.ThrowIfCancellationRequested();
1240 flag = await cr.ReadContentFromAsync(this, r).ConfigureAwait(continueOnCapturedContext: false);
1241 if (flag)
1242 {
1243 flag = await r.ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
1244 }
1245 }
1246 while (flag);
1247 }
1248
1250 {
1251 if ((o & (LoadOptions.SetBaseUri | LoadOptions.SetLineInfo)) == 0)
1252 {
1254 return;
1255 }
1256 if (r.ReadState != ReadState.Interactive)
1257 {
1259 }
1260 ContentReader cr = new ContentReader(this, r, o);
1261 bool flag;
1262 do
1263 {
1264 cancellationToken.ThrowIfCancellationRequested();
1265 flag = await cr.ReadContentFromAsync(this, r, o).ConfigureAwait(continueOnCapturedContext: false);
1266 if (flag)
1267 {
1268 flag = await r.ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
1269 }
1270 }
1271 while (flag);
1272 }
1273
1274 internal void RemoveNode(XNode n)
1275 {
1277 if (n.parent != this)
1278 {
1280 }
1282 while (xNode.next != n)
1283 {
1284 xNode = xNode.next;
1285 }
1286 if (xNode == n)
1287 {
1288 content = null;
1289 }
1290 else
1291 {
1292 if (content == n)
1293 {
1294 content = xNode;
1295 }
1296 xNode.next = n.next;
1297 }
1298 n.parent = null;
1299 n.next = null;
1300 if (flag)
1301 {
1303 }
1304 }
1305
1307 {
1309 if (xNode != null)
1310 {
1311 do
1312 {
1313 XNode xNode2 = xNode.next;
1314 xNode.parent = null;
1315 xNode.next = null;
1316 xNode = xNode2;
1317 }
1318 while (xNode != content);
1319 }
1320 content = null;
1321 }
1322
1323 internal virtual void ValidateNode(XNode node, XNode previous)
1324 {
1325 }
1326
1327 internal virtual void ValidateString(string s)
1328 {
1329 }
1330
1332 {
1333 if (content == null)
1334 {
1335 return;
1336 }
1337 if (content is string text)
1338 {
1339 if (this is XDocument)
1340 {
1341 writer.WriteWhitespace(text);
1342 }
1343 else
1344 {
1345 writer.WriteString(text);
1346 }
1347 return;
1348 }
1350 do
1351 {
1352 xNode = xNode.next;
1353 xNode.WriteTo(writer);
1354 }
1355 while (xNode != content);
1356 }
1357
1359 {
1360 if (content == null)
1361 {
1362 return;
1363 }
1364 if (content is string text)
1365 {
1366 cancellationToken.ThrowIfCancellationRequested();
1367 Task task = ((!(this is XDocument)) ? writer.WriteStringAsync(text) : writer.WriteWhitespaceAsync(text));
1368 await task.ConfigureAwait(continueOnCapturedContext: false);
1369 return;
1370 }
1371 XNode i = (XNode)content;
1372 do
1373 {
1374 i = i.next;
1375 await i.WriteToAsync(writer, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
1376 }
1377 while (i != content);
1378 }
1379
1380 private static void AddContentToList(List<object> list, object content)
1381 {
1382 IEnumerable enumerable = ((content is string) ? null : (content as IEnumerable));
1383 if (enumerable == null)
1384 {
1385 list.Add(content);
1386 return;
1387 }
1388 foreach (object item in enumerable)
1389 {
1390 if (item != null)
1391 {
1393 }
1394 }
1395 }
1396
1397 [return: NotNullIfNotNull("content")]
1398 internal static object GetContentSnapshot(object content)
1399 {
1400 if (content is string || !(content is IEnumerable))
1401 {
1402 return content;
1403 }
1406 return list;
1407 }
1408}
static string Argument_XObjectValue
Definition SR.cs:36
static string InvalidOperation_ExternalCode
Definition SR.cs:50
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_ConvertToString
Definition SR.cs:20
static string InvalidOperation_ExpectedInteractive
Definition SR.cs:46
static string InvalidOperation_UnresolvedEntityReference
Definition SR.cs:60
static string InvalidOperation_UnexpectedNodeType
Definition SR.cs:58
Definition SR.cs:7
StringBuilder Append(char value, int repeatCount)
static int CompareExchange(ref int location1, int value, int comparand)
async ValueTask< bool > ReadContentFromAsync(XContainer rootContainer, XmlReader r)
bool ReadContentFrom(XContainer rootContainer, XmlReader r)
Definition XContainer.cs:36
bool ReadContentFrom(XContainer rootContainer, XmlReader r, LoadOptions o)
ContentReader(XContainer rootContainer, XmlReader r, LoadOptions o)
Definition XContainer.cs:29
async ValueTask< bool > ReadContentFromAsync(XContainer rootContainer, XmlReader r, LoadOptions o)
ContentReader(XContainer rootContainer)
Definition XContainer.cs:24
async Task WriteContentToAsync(XmlWriter writer, CancellationToken cancellationToken)
IEnumerable< XNode > Nodes()
void AddContentSkipNotify(object content)
void AddFirst(params object?[] content)
virtual void ValidateNode(XNode node, XNode previous)
bool ContentsEqual(XContainer e)
static object GetContentSnapshot(object content)
void ReadContentFrom(XmlReader r, LoadOptions o)
static void AddContentToList(List< object > list, object content)
void AddNodeSkipNotify(XNode n)
IEnumerable< XElement > Descendants()
void AddStringSkipNotify(string s)
IEnumerable< XNode > DescendantNodes()
async Task ReadContentFromAsync(XmlReader r, CancellationToken cancellationToken)
XElement? Element(XName name)
void ReadContentFrom(XmlReader r)
void Add(params object?[] content)
virtual void AddAttribute(XAttribute a)
void ReplaceNodes(params object?[] content)
virtual void ValidateString(string s)
void Add(object? content)
IEnumerable< XElement > Elements(XName? name)
IEnumerable< XNode > GetDescendantNodes(bool self)
IEnumerable< XElement > Elements()
async Task ReadContentFromAsync(XmlReader r, LoadOptions o, CancellationToken cancellationToken)
static string GetStringValue(object value)
IEnumerable< XElement > GetElements(XName name)
string CollectText(ref XNode n)
void AddFirst(object? content)
IEnumerable< XElement > GetDescendants(XName name, bool self)
XContainer(XContainer other)
IEnumerable< XElement > Descendants(XName? name)
void ReplaceNodes(object? content)
virtual void AddAttributeSkipNotify(XAttribute a)
void AppendNodeSkipNotify(XNode n)
void WriteContentTo(XmlWriter writer)
override void AppendText(StringBuilder sb)
void AppendAttributeSkipNotify(XAttribute a)
Definition XElement.cs:1023
static IEnumerable< XElement > EmptySequence
Definition XElement.cs:29
XName GetName(string localName)
Definition XNamespace.cs:37
static readonly XObjectChangeEventArgs Value
static readonly XObjectChangeEventArgs Add
static readonly XObjectChangeEventArgs Remove
XContainer parent
Definition XObject.cs:7
bool NotifyChanging(object sender, XObjectChangeEventArgs e)
Definition XObject.cs:428
void SetLineInfo(int lineNumber, int linePosition)
Definition XObject.cs:462
bool NotifyChanged(object sender, XObjectChangeEventArgs e)
Definition XObject.cs:399
void SetBaseUri(string baseUri)
Definition XObject.cs:457
static string ToString(bool value)
static XmlWriter Create(string outputFileName)
Definition XmlWriter.cs:468
void Add(object content)
Definition Inserter.cs:20
XNamespace Get(string namespaceName)