Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlSubtreeReader.cs
Go to the documentation of this file.
3
4namespace System.Xml;
5
7{
8 private sealed class NodeData
9 {
10 internal XmlNodeType type;
11
12 internal string localName;
13
14 internal string prefix;
15
16 internal string name;
17
18 internal string namespaceUri;
19
20 internal string value;
21
22 internal NodeData(XmlNodeType nodeType, string localName, string prefix, string name, string namespaceUri, string value)
23 {
24 type = nodeType;
30 }
31
32 internal void Set(XmlNodeType nodeType, string localName, string prefix, string name, string namespaceUri, string value)
33 {
34 type = nodeType;
40 }
41 }
42
57
58 private readonly int _initialDepth;
59
60 private State _state;
61
63
65
66 private int _nsAttrCount;
67
68 private int _curNsAttr = -1;
69
70 private readonly string _xmlns;
71
72 private readonly string _xmlnsUri;
73
74 private int _nsIncReadOffset;
75
77
78 private bool _useCurNode;
79
81
82 private readonly NodeData _tmpNode;
83
85
86 public override XmlNodeType NodeType
87 {
88 get
89 {
90 if (!_useCurNode)
91 {
92 return reader.NodeType;
93 }
94 return _curNode.type;
95 }
96 }
97
98 public override string Name
99 {
100 get
101 {
102 if (!_useCurNode)
103 {
104 return reader.Name;
105 }
106 return _curNode.name;
107 }
108 }
109
110 public override string LocalName
111 {
112 get
113 {
114 if (!_useCurNode)
115 {
116 return reader.LocalName;
117 }
118 return _curNode.localName;
119 }
120 }
121
122 public override string NamespaceURI
123 {
124 get
125 {
126 if (!_useCurNode)
127 {
128 return reader.NamespaceURI;
129 }
130 return _curNode.namespaceUri;
131 }
132 }
133
134 public override string Prefix
135 {
136 get
137 {
138 if (!_useCurNode)
139 {
140 return reader.Prefix;
141 }
142 return _curNode.prefix;
143 }
144 }
145
146 public override string Value
147 {
148 get
149 {
150 if (!_useCurNode)
151 {
152 return reader.Value;
153 }
154 return _curNode.value;
155 }
156 }
157
158 public override int Depth
159 {
160 get
161 {
162 int num = reader.Depth - _initialDepth;
163 if (_curNsAttr != -1)
164 {
165 num = ((_curNode.type != XmlNodeType.Text) ? (num + 1) : (num + 2));
166 }
167 return num;
168 }
169 }
170
171 public override string BaseURI => reader.BaseURI;
172
173 public override bool IsEmptyElement => reader.IsEmptyElement;
174
175 public override bool EOF
176 {
177 get
178 {
179 if (_state != State.EndOfFile)
180 {
181 return _state == State.Closed;
182 }
183 return true;
184 }
185 }
186
187 public override ReadState ReadState
188 {
189 get
190 {
191 if (reader.ReadState == ReadState.Error)
192 {
193 return ReadState.Error;
194 }
195 if (_state <= State.Closed)
196 {
197 return (ReadState)_state;
198 }
199 return ReadState.Interactive;
200 }
201 }
202
204
205 public override int AttributeCount
206 {
207 get
208 {
210 {
211 return 0;
212 }
214 }
215 }
216
218
220
222 {
223 get
224 {
226 {
227 return xmlLineInfo.LineNumber;
228 }
229 return 0;
230 }
231 }
232
234 {
235 get
236 {
238 {
239 return xmlLineInfo.LinePosition;
240 }
241 return 0;
242 }
243 }
244
245 private bool InAttributeActiveState => (0x62 & (1 << (int)_state)) != 0;
246
247 private bool InNamespaceActiveState => (0x7E2 & (1 << (int)_state)) != 0;
248
250 : base(reader)
251 {
253 _state = State.Initial;
255 _xmlns = reader.NameTable.Add("xmlns");
256 _xmlnsUri = reader.NameTable.Add("http://www.w3.org/2000/xmlns/");
257 _tmpNode = new NodeData(XmlNodeType.None, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
259 }
260
261 public override string GetAttribute(string name)
262 {
264 {
265 return null;
266 }
267 string attribute = reader.GetAttribute(name);
268 if (attribute != null)
269 {
270 return attribute;
271 }
272 for (int i = 0; i < _nsAttrCount; i++)
273 {
274 if (name == _nsAttributes[i].name)
275 {
276 return _nsAttributes[i].value;
277 }
278 }
279 return null;
280 }
281
282 public override string GetAttribute(string name, string namespaceURI)
283 {
285 {
286 return null;
287 }
289 if (attribute != null)
290 {
291 return attribute;
292 }
293 for (int i = 0; i < _nsAttrCount; i++)
294 {
295 if (name == _nsAttributes[i].localName && namespaceURI == _xmlnsUri)
296 {
297 return _nsAttributes[i].value;
298 }
299 }
300 return null;
301 }
302
303 public override string GetAttribute(int i)
304 {
306 {
307 throw new ArgumentOutOfRangeException("i");
308 }
309 int attributeCount = reader.AttributeCount;
310 if (i < attributeCount)
311 {
312 return reader.GetAttribute(i);
313 }
314 if (i - attributeCount < _nsAttrCount)
315 {
316 return _nsAttributes[i - attributeCount].value;
317 }
318 throw new ArgumentOutOfRangeException("i");
319 }
320
321 public override bool MoveToAttribute(string name)
322 {
324 {
325 return false;
326 }
327 if (reader.MoveToAttribute(name))
328 {
329 _curNsAttr = -1;
330 _useCurNode = false;
331 return true;
332 }
333 for (int i = 0; i < _nsAttrCount; i++)
334 {
335 if (name == _nsAttributes[i].name)
336 {
338 return true;
339 }
340 }
341 return false;
342 }
343
344 public override bool MoveToAttribute(string name, string ns)
345 {
347 {
348 return false;
349 }
350 if (reader.MoveToAttribute(name, ns))
351 {
352 _curNsAttr = -1;
353 _useCurNode = false;
354 return true;
355 }
356 for (int i = 0; i < _nsAttrCount; i++)
357 {
358 if (name == _nsAttributes[i].localName && ns == _xmlnsUri)
359 {
361 return true;
362 }
363 }
364 return false;
365 }
366
367 public override void MoveToAttribute(int i)
368 {
370 {
371 throw new ArgumentOutOfRangeException("i");
372 }
373 int attributeCount = reader.AttributeCount;
374 if (i < attributeCount)
375 {
377 _curNsAttr = -1;
378 _useCurNode = false;
379 return;
380 }
381 if (i - attributeCount < _nsAttrCount)
382 {
383 MoveToNsAttribute(i - attributeCount);
384 return;
385 }
386 throw new ArgumentOutOfRangeException("i");
387 }
388
389 public override bool MoveToFirstAttribute()
390 {
392 {
393 return false;
394 }
396 {
397 _useCurNode = false;
398 return true;
399 }
400 if (_nsAttrCount > 0)
401 {
403 return true;
404 }
405 return false;
406 }
407
408 public override bool MoveToNextAttribute()
409 {
411 {
412 return false;
413 }
415 {
416 return true;
417 }
418 if (_curNsAttr + 1 < _nsAttrCount)
419 {
421 return true;
422 }
423 return false;
424 }
425
426 public override bool MoveToElement()
427 {
429 {
430 return false;
431 }
432 _useCurNode = false;
433 if (_curNsAttr >= 0)
434 {
435 _curNsAttr = -1;
436 return true;
437 }
438 return reader.MoveToElement();
439 }
440
441 public override bool ReadAttributeValue()
442 {
444 {
445 return false;
446 }
447 if (_curNsAttr == -1)
448 {
449 return reader.ReadAttributeValue();
450 }
451 if (_curNode.type == XmlNodeType.Text)
452 {
453 return false;
454 }
458 return true;
459 }
460
461 public override bool Read()
462 {
463 switch (_state)
464 {
465 case State.Initial:
466 _useCurNode = false;
467 _state = State.Interactive;
469 return true;
470 case State.Interactive:
471 _curNsAttr = -1;
472 _useCurNode = false;
475 {
476 _state = State.EndOfFile;
477 SetEmptyNode();
478 return false;
479 }
480 if (reader.Read())
481 {
483 return true;
484 }
485 SetEmptyNode();
486 return false;
487 case State.Error:
488 case State.EndOfFile:
489 case State.Closed:
490 return false;
491 case State.PopNamespaceScope:
493 goto case State.ClearNsAttributes;
494 case State.ClearNsAttributes:
495 _nsAttrCount = 0;
496 _state = State.Interactive;
497 goto case State.Interactive;
498 case State.ReadElementContentAsBase64:
499 case State.ReadElementContentAsBinHex:
501 {
502 return false;
503 }
504 return Read();
505 case State.ReadContentAsBase64:
506 case State.ReadContentAsBinHex:
508 {
509 return false;
510 }
511 return Read();
512 default:
513 return false;
514 }
515 }
516
517 public override void Close()
518 {
519 if (_state == State.Closed)
520 {
521 return;
522 }
523 try
524 {
525 if (_state != State.EndOfFile)
526 {
529 {
530 reader.Read();
531 }
532 while (reader.Depth > _initialDepth && reader.Read())
533 {
534 }
535 }
536 }
537 catch
538 {
539 }
540 finally
541 {
542 _curNsAttr = -1;
543 _useCurNode = false;
544 _state = State.Closed;
545 SetEmptyNode();
546 }
547 }
548
549 public override void Skip()
550 {
551 switch (_state)
552 {
553 case State.Initial:
554 Read();
555 break;
556 case State.Interactive:
557 _curNsAttr = -1;
558 _useCurNode = false;
561 {
563 {
564 while (reader.NodeType != XmlNodeType.EndElement && reader.Depth > _initialDepth)
565 {
566 reader.Skip();
567 }
568 }
569 _state = State.EndOfFile;
570 SetEmptyNode();
571 }
572 else
573 {
575 {
577 }
578 reader.Skip();
580 }
581 break;
582 case State.EndOfFile:
583 case State.Closed:
584 break;
585 case State.PopNamespaceScope:
587 goto case State.ClearNsAttributes;
588 case State.ClearNsAttributes:
589 _nsAttrCount = 0;
590 _state = State.Interactive;
591 goto case State.Interactive;
592 case State.ReadElementContentAsBase64:
593 case State.ReadElementContentAsBinHex:
595 {
596 Skip();
597 }
598 break;
599 case State.ReadContentAsBase64:
600 case State.ReadContentAsBinHex:
602 {
603 Skip();
604 }
605 break;
606 case State.Error:
607 break;
608 }
609 }
610
611 public override object ReadContentAsObject()
612 {
613 try
614 {
615 InitReadContentAsType("ReadContentAsObject");
616 object result = reader.ReadContentAsObject();
618 return result;
619 }
620 catch
621 {
622 _state = State.Error;
623 throw;
624 }
625 }
626
627 public override bool ReadContentAsBoolean()
628 {
629 try
630 {
631 InitReadContentAsType("ReadContentAsBoolean");
632 bool result = reader.ReadContentAsBoolean();
634 return result;
635 }
636 catch
637 {
638 _state = State.Error;
639 throw;
640 }
641 }
642
644 {
645 try
646 {
647 InitReadContentAsType("ReadContentAsDateTime");
650 return result;
651 }
652 catch
653 {
654 _state = State.Error;
655 throw;
656 }
657 }
658
659 public override double ReadContentAsDouble()
660 {
661 try
662 {
663 InitReadContentAsType("ReadContentAsDouble");
664 double result = reader.ReadContentAsDouble();
666 return result;
667 }
668 catch
669 {
670 _state = State.Error;
671 throw;
672 }
673 }
674
675 public override float ReadContentAsFloat()
676 {
677 try
678 {
679 InitReadContentAsType("ReadContentAsFloat");
680 float result = reader.ReadContentAsFloat();
682 return result;
683 }
684 catch
685 {
686 _state = State.Error;
687 throw;
688 }
689 }
690
691 public override decimal ReadContentAsDecimal()
692 {
693 try
694 {
695 InitReadContentAsType("ReadContentAsDecimal");
696 decimal result = reader.ReadContentAsDecimal();
698 return result;
699 }
700 catch
701 {
702 _state = State.Error;
703 throw;
704 }
705 }
706
707 public override int ReadContentAsInt()
708 {
709 try
710 {
711 InitReadContentAsType("ReadContentAsInt");
712 int result = reader.ReadContentAsInt();
714 return result;
715 }
716 catch
717 {
718 _state = State.Error;
719 throw;
720 }
721 }
722
723 public override long ReadContentAsLong()
724 {
725 try
726 {
727 InitReadContentAsType("ReadContentAsLong");
728 long result = reader.ReadContentAsLong();
730 return result;
731 }
732 catch
733 {
734 _state = State.Error;
735 throw;
736 }
737 }
738
739 public override string ReadContentAsString()
740 {
741 try
742 {
743 InitReadContentAsType("ReadContentAsString");
744 string result = reader.ReadContentAsString();
746 return result;
747 }
748 catch
749 {
750 _state = State.Error;
751 throw;
752 }
753 }
754
756 {
757 try
758 {
759 InitReadContentAsType("ReadContentAs");
762 return result;
763 }
764 catch
765 {
766 _state = State.Error;
767 throw;
768 }
769 }
770
771 public override int ReadContentAsBase64(byte[] buffer, int index, int count)
772 {
773 switch (_state)
774 {
775 case State.Initial:
776 case State.Error:
777 case State.EndOfFile:
778 case State.Closed:
779 return 0;
780 case State.PopNamespaceScope:
781 case State.ClearNsAttributes:
782 switch (NodeType)
783 {
784 case XmlNodeType.Element:
785 throw CreateReadContentAsException("ReadContentAsBase64");
786 case XmlNodeType.EndElement:
787 return 0;
788 case XmlNodeType.Attribute:
790 {
792 if (count == 0)
793 {
794 return 0;
795 }
796 if (_nsIncReadOffset == 0)
797 {
799 {
801 }
802 else
803 {
805 }
806 }
807 if (_nsIncReadOffset == _curNode.value.Length)
808 {
809 return 0;
810 }
814 }
815 goto case XmlNodeType.Text;
816 case XmlNodeType.Text:
818 default:
819 return 0;
820 }
821 case State.Interactive:
822 _state = State.ReadContentAsBase64;
823 goto case State.ReadContentAsBase64;
824 case State.ReadContentAsBase64:
825 {
827 if (num == 0)
828 {
829 _state = State.Interactive;
831 }
832 return num;
833 }
834 case State.ReadElementContentAsBase64:
835 case State.ReadElementContentAsBinHex:
836 case State.ReadContentAsBinHex:
838 default:
839 return 0;
840 }
841 }
842
843 public override int ReadElementContentAsBase64(byte[] buffer, int index, int count)
844 {
845 switch (_state)
846 {
847 case State.Initial:
848 case State.Error:
849 case State.EndOfFile:
850 case State.Closed:
851 return 0;
852 case State.Interactive:
853 case State.PopNamespaceScope:
854 case State.ClearNsAttributes:
855 if (!InitReadElementContentAsBinary(State.ReadElementContentAsBase64))
856 {
857 return 0;
858 }
859 goto case State.ReadElementContentAsBase64;
860 case State.ReadElementContentAsBase64:
861 {
863 if (num > 0 || count == 0)
864 {
865 return num;
866 }
867 if (NodeType != XmlNodeType.EndElement)
868 {
870 }
871 _state = State.Interactive;
874 {
875 _state = State.EndOfFile;
876 SetEmptyNode();
877 }
878 else
879 {
880 Read();
881 }
882 return 0;
883 }
884 case State.ReadElementContentAsBinHex:
885 case State.ReadContentAsBase64:
886 case State.ReadContentAsBinHex:
888 default:
889 return 0;
890 }
891 }
892
893 public override int ReadContentAsBinHex(byte[] buffer, int index, int count)
894 {
895 switch (_state)
896 {
897 case State.Initial:
898 case State.Error:
899 case State.EndOfFile:
900 case State.Closed:
901 return 0;
902 case State.PopNamespaceScope:
903 case State.ClearNsAttributes:
904 switch (NodeType)
905 {
906 case XmlNodeType.Element:
907 throw CreateReadContentAsException("ReadContentAsBinHex");
908 case XmlNodeType.EndElement:
909 return 0;
910 case XmlNodeType.Attribute:
912 {
914 if (count == 0)
915 {
916 return 0;
917 }
918 if (_nsIncReadOffset == 0)
919 {
921 {
923 }
924 else
925 {
927 }
928 }
929 if (_nsIncReadOffset == _curNode.value.Length)
930 {
931 return 0;
932 }
936 }
937 goto case XmlNodeType.Text;
938 case XmlNodeType.Text:
940 default:
941 return 0;
942 }
943 case State.Interactive:
944 _state = State.ReadContentAsBinHex;
945 goto case State.ReadContentAsBinHex;
946 case State.ReadContentAsBinHex:
947 {
949 if (num == 0)
950 {
951 _state = State.Interactive;
953 }
954 return num;
955 }
956 case State.ReadElementContentAsBase64:
957 case State.ReadElementContentAsBinHex:
958 case State.ReadContentAsBase64:
960 default:
961 return 0;
962 }
963 }
964
965 public override int ReadElementContentAsBinHex(byte[] buffer, int index, int count)
966 {
967 switch (_state)
968 {
969 case State.Initial:
970 case State.Error:
971 case State.EndOfFile:
972 case State.Closed:
973 return 0;
974 case State.Interactive:
975 case State.PopNamespaceScope:
976 case State.ClearNsAttributes:
977 if (!InitReadElementContentAsBinary(State.ReadElementContentAsBinHex))
978 {
979 return 0;
980 }
981 goto case State.ReadElementContentAsBinHex;
982 case State.ReadElementContentAsBinHex:
983 {
985 if (num > 0 || count == 0)
986 {
987 return num;
988 }
989 if (NodeType != XmlNodeType.EndElement)
990 {
992 }
993 _state = State.Interactive;
996 {
997 _state = State.EndOfFile;
998 SetEmptyNode();
999 }
1000 else
1001 {
1002 Read();
1003 }
1004 return 0;
1005 }
1006 case State.ReadElementContentAsBase64:
1007 case State.ReadContentAsBase64:
1008 case State.ReadContentAsBinHex:
1010 default:
1011 return 0;
1012 }
1013 }
1014
1015 public override int ReadValueChunk(char[] buffer, int index, int count)
1016 {
1017 switch (_state)
1018 {
1019 case State.Initial:
1020 case State.Error:
1021 case State.EndOfFile:
1022 case State.Closed:
1023 return 0;
1024 case State.PopNamespaceScope:
1025 case State.ClearNsAttributes:
1026 if (_curNsAttr != -1 && reader.CanReadValueChunk)
1027 {
1030 if (num > count)
1031 {
1032 num = count;
1033 }
1034 if (num > 0)
1035 {
1037 }
1038 _nsIncReadOffset += num;
1039 return num;
1040 }
1041 goto case State.Interactive;
1042 case State.Interactive:
1044 case State.ReadElementContentAsBase64:
1045 case State.ReadElementContentAsBinHex:
1046 case State.ReadContentAsBase64:
1047 case State.ReadContentAsBinHex:
1049 default:
1050 return 0;
1051 }
1052 }
1053
1054 public override string LookupNamespace(string prefix)
1055 {
1056 return ((IXmlNamespaceResolver)this).LookupNamespace(prefix);
1057 }
1058
1059 protected override void Dispose(bool disposing)
1060 {
1061 Close();
1062 }
1063
1065 {
1066 return reader is IXmlLineInfo;
1067 }
1068
1077
1079 {
1081 {
1082 return null;
1083 }
1085 }
1086
1088 {
1090 {
1091 return null;
1092 }
1094 }
1095
1096 private void ProcessNamespaces()
1097 {
1098 switch (reader.NodeType)
1099 {
1100 case XmlNodeType.Element:
1101 {
1103 string prefix = reader.Prefix;
1106 {
1108 }
1110 {
1111 do
1112 {
1116 {
1117 if (prefix.Length == 0)
1118 {
1120 RemoveNamespace(string.Empty, _xmlns);
1121 }
1122 else
1123 {
1127 }
1128 }
1129 else if (prefix.Length != 0 && _nsManager.LookupNamespace(prefix) != namespaceURI)
1130 {
1132 }
1133 }
1134 while (reader.MoveToNextAttribute());
1136 }
1138 {
1139 _state = State.PopNamespaceScope;
1140 }
1141 break;
1142 }
1143 case XmlNodeType.EndElement:
1144 _state = State.PopNamespaceScope;
1145 break;
1146 }
1147 }
1148
1149 private void AddNamespace(string prefix, string ns)
1150 {
1152 int num = _nsAttrCount++;
1153 if (_nsAttributes == null)
1154 {
1156 }
1157 if (num == _nsAttributes.Length)
1158 {
1162 }
1163 string localName;
1164 string prefix2;
1165 string name;
1166 if (prefix.Length == 0)
1167 {
1168 localName = _xmlns;
1169 prefix2 = string.Empty;
1170 name = _xmlns;
1171 }
1172 else
1173 {
1174 localName = prefix;
1175 prefix2 = _xmlns;
1176 name = reader.NameTable.Add(_xmlns + ":" + prefix);
1177 }
1178 if (_nsAttributes[num] == null)
1179 {
1180 _nsAttributes[num] = new NodeData(XmlNodeType.Attribute, localName, prefix2, name, _xmlnsUri, ns);
1181 }
1182 else
1183 {
1184 _nsAttributes[num].Set(XmlNodeType.Attribute, localName, prefix2, name, _xmlnsUri, ns);
1185 }
1186 _state = State.ClearNsAttributes;
1187 _curNsAttr = -1;
1188 }
1189
1190 private void RemoveNamespace(string prefix, string localName)
1191 {
1192 for (int i = 0; i < _nsAttrCount; i++)
1193 {
1194 if (Ref.Equal(prefix, _nsAttributes[i].prefix) && Ref.Equal(localName, _nsAttributes[i].localName))
1195 {
1196 if (i < _nsAttrCount - 1)
1197 {
1201 }
1202 _nsAttrCount--;
1203 break;
1204 }
1205 }
1206 }
1207
1208 private void MoveToNsAttribute(int index)
1209 {
1211 _curNsAttr = index;
1212 _nsIncReadOffset = 0;
1214 }
1215
1217 {
1218 if (NodeType != XmlNodeType.Element)
1219 {
1220 throw reader.CreateReadElementContentAsException("ReadElementContentAsBase64");
1221 }
1223 if (!Read() || isEmptyElement)
1224 {
1225 return false;
1226 }
1227 switch (NodeType)
1228 {
1229 case XmlNodeType.Element:
1231 case XmlNodeType.EndElement:
1233 Read();
1234 return false;
1235 default:
1237 return true;
1238 }
1239 }
1240
1242 {
1243 byte[] buffer = new byte[256];
1244 if (_state == State.ReadElementContentAsBase64)
1245 {
1246 while (reader.ReadContentAsBase64(buffer, 0, 256) > 0)
1247 {
1248 }
1249 }
1250 else
1251 {
1252 while (reader.ReadContentAsBinHex(buffer, 0, 256) > 0)
1253 {
1254 }
1255 }
1256 if (NodeType != XmlNodeType.EndElement)
1257 {
1259 }
1260 _state = State.Interactive;
1262 if (reader.Depth == _initialDepth)
1263 {
1264 _state = State.EndOfFile;
1265 SetEmptyNode();
1266 return false;
1267 }
1268 return Read();
1269 }
1270
1272 {
1273 byte[] buffer = new byte[256];
1274 if (_state == State.ReadContentAsBase64)
1275 {
1276 while (reader.ReadContentAsBase64(buffer, 0, 256) > 0)
1277 {
1278 }
1279 }
1280 else
1281 {
1282 while (reader.ReadContentAsBinHex(buffer, 0, 256) > 0)
1283 {
1284 }
1285 }
1286 _state = State.Interactive;
1288 if (reader.Depth == _initialDepth)
1289 {
1290 _state = State.EndOfFile;
1291 SetEmptyNode();
1292 return false;
1293 }
1294 return true;
1295 }
1296
1297 private void SetEmptyNode()
1298 {
1300 _tmpNode.value = string.Empty;
1302 _useCurNode = true;
1303 }
1304
1306 {
1307 _curNode = node;
1308 _useCurNode = true;
1309 }
1310
1312 {
1313 switch (_state)
1314 {
1315 case State.Initial:
1316 case State.Error:
1317 case State.EndOfFile:
1318 case State.Closed:
1320 case State.Interactive:
1321 break;
1322 case State.PopNamespaceScope:
1323 case State.ClearNsAttributes:
1324 break;
1325 case State.ReadElementContentAsBase64:
1326 case State.ReadElementContentAsBinHex:
1327 case State.ReadContentAsBase64:
1328 case State.ReadContentAsBinHex:
1330 default:
1332 }
1333 }
1334
1336 {
1337 switch (NodeType)
1338 {
1339 case XmlNodeType.Element:
1341 break;
1342 case XmlNodeType.EndElement:
1343 _state = State.PopNamespaceScope;
1344 break;
1345 }
1346 }
1347
1348 private void CheckBuffer(Array buffer, int index, int count)
1349 {
1350 if (buffer == null)
1351 {
1352 throw new ArgumentNullException("buffer");
1353 }
1354 if (count < 0)
1355 {
1356 throw new ArgumentOutOfRangeException("count");
1357 }
1358 if (index < 0)
1359 {
1360 throw new ArgumentOutOfRangeException("index");
1361 }
1362 if (buffer.Length - index < count)
1363 {
1364 throw new ArgumentOutOfRangeException("count");
1365 }
1366 }
1367
1368 public override Task<string> GetValueAsync()
1369 {
1370 if (_useCurNode)
1371 {
1372 return Task.FromResult(_curNode.value);
1373 }
1374 return reader.GetValueAsync();
1375 }
1376
1377 public override async Task<bool> ReadAsync()
1378 {
1379 switch (_state)
1380 {
1381 case State.Initial:
1382 _useCurNode = false;
1383 _state = State.Interactive;
1385 return true;
1386 case State.Interactive:
1387 _curNsAttr = -1;
1388 _useCurNode = false;
1391 {
1392 _state = State.EndOfFile;
1393 SetEmptyNode();
1394 return false;
1395 }
1396 if (await reader.ReadAsync().ConfigureAwait(continueOnCapturedContext: false))
1397 {
1399 return true;
1400 }
1401 SetEmptyNode();
1402 return false;
1403 case State.Error:
1404 case State.EndOfFile:
1405 case State.Closed:
1406 return false;
1407 case State.PopNamespaceScope:
1409 goto case State.ClearNsAttributes;
1410 case State.ClearNsAttributes:
1411 _nsAttrCount = 0;
1412 _state = State.Interactive;
1413 goto case State.Interactive;
1414 case State.ReadElementContentAsBase64:
1415 case State.ReadElementContentAsBinHex:
1417 {
1418 return false;
1419 }
1420 return await ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
1421 case State.ReadContentAsBase64:
1422 case State.ReadContentAsBinHex:
1423 if (!(await FinishReadContentAsBinaryAsync().ConfigureAwait(continueOnCapturedContext: false)))
1424 {
1425 return false;
1426 }
1427 return await ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
1428 default:
1429 return false;
1430 }
1431 }
1432
1433 public override async Task SkipAsync()
1434 {
1435 switch (_state)
1436 {
1437 case State.Initial:
1438 await ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
1439 break;
1440 case State.Interactive:
1441 _curNsAttr = -1;
1442 _useCurNode = false;
1444 if (reader.Depth == _initialDepth)
1445 {
1446 if (reader.NodeType == XmlNodeType.Element && !reader.IsEmptyElement && await reader.ReadAsync().ConfigureAwait(continueOnCapturedContext: false))
1447 {
1448 while (reader.NodeType != XmlNodeType.EndElement && reader.Depth > _initialDepth)
1449 {
1450 await reader.SkipAsync().ConfigureAwait(continueOnCapturedContext: false);
1451 }
1452 }
1453 _state = State.EndOfFile;
1454 SetEmptyNode();
1455 }
1456 else
1457 {
1458 if (reader.NodeType == XmlNodeType.Element && !reader.IsEmptyElement)
1459 {
1461 }
1462 await reader.SkipAsync().ConfigureAwait(continueOnCapturedContext: false);
1464 }
1465 break;
1466 case State.EndOfFile:
1467 case State.Closed:
1468 break;
1469 case State.PopNamespaceScope:
1471 goto case State.ClearNsAttributes;
1472 case State.ClearNsAttributes:
1473 _nsAttrCount = 0;
1474 _state = State.Interactive;
1475 goto case State.Interactive;
1476 case State.ReadElementContentAsBase64:
1477 case State.ReadElementContentAsBinHex:
1479 {
1480 await SkipAsync().ConfigureAwait(continueOnCapturedContext: false);
1481 }
1482 break;
1483 case State.ReadContentAsBase64:
1484 case State.ReadContentAsBinHex:
1486 {
1487 await SkipAsync().ConfigureAwait(continueOnCapturedContext: false);
1488 }
1489 break;
1490 case State.Error:
1491 break;
1492 }
1493 }
1494
1496 {
1497 try
1498 {
1499 InitReadContentAsType("ReadContentAsObject");
1500 object result = await reader.ReadContentAsObjectAsync().ConfigureAwait(continueOnCapturedContext: false);
1502 return result;
1503 }
1504 catch
1505 {
1506 _state = State.Error;
1507 throw;
1508 }
1509 }
1510
1512 {
1513 try
1514 {
1515 InitReadContentAsType("ReadContentAsString");
1516 string result = await reader.ReadContentAsStringAsync().ConfigureAwait(continueOnCapturedContext: false);
1518 return result;
1519 }
1520 catch
1521 {
1522 _state = State.Error;
1523 throw;
1524 }
1525 }
1526
1528 {
1529 try
1530 {
1531 InitReadContentAsType("ReadContentAs");
1534 return result;
1535 }
1536 catch
1537 {
1538 _state = State.Error;
1539 throw;
1540 }
1541 }
1542
1543 public override async Task<int> ReadContentAsBase64Async(byte[] buffer, int index, int count)
1544 {
1545 switch (_state)
1546 {
1547 case State.Initial:
1548 case State.Error:
1549 case State.EndOfFile:
1550 case State.Closed:
1551 return 0;
1552 case State.PopNamespaceScope:
1553 case State.ClearNsAttributes:
1554 switch (NodeType)
1555 {
1556 case XmlNodeType.Element:
1557 throw CreateReadContentAsException("ReadContentAsBase64");
1558 case XmlNodeType.EndElement:
1559 return 0;
1560 case XmlNodeType.Attribute:
1562 {
1564 if (count == 0)
1565 {
1566 return 0;
1567 }
1568 if (_nsIncReadOffset == 0)
1569 {
1570 if (_binDecoder != null && _binDecoder is Base64Decoder)
1571 {
1573 }
1574 else
1575 {
1576 _binDecoder = new Base64Decoder();
1577 }
1578 }
1579 if (_nsIncReadOffset == _curNode.value.Length)
1580 {
1581 return 0;
1582 }
1586 }
1587 goto case XmlNodeType.Text;
1588 case XmlNodeType.Text:
1590 default:
1591 return 0;
1592 }
1593 case State.Interactive:
1594 _state = State.ReadContentAsBase64;
1595 goto case State.ReadContentAsBase64;
1596 case State.ReadContentAsBase64:
1597 {
1599 if (num == 0)
1600 {
1601 _state = State.Interactive;
1603 }
1604 return num;
1605 }
1606 case State.ReadElementContentAsBase64:
1607 case State.ReadElementContentAsBinHex:
1608 case State.ReadContentAsBinHex:
1610 default:
1611 return 0;
1612 }
1613 }
1614
1616 {
1617 switch (_state)
1618 {
1619 case State.Initial:
1620 case State.Error:
1621 case State.EndOfFile:
1622 case State.Closed:
1623 return 0;
1624 case State.Interactive:
1625 case State.PopNamespaceScope:
1626 case State.ClearNsAttributes:
1627 if (!(await InitReadElementContentAsBinaryAsync(State.ReadElementContentAsBase64).ConfigureAwait(continueOnCapturedContext: false)))
1628 {
1629 return 0;
1630 }
1631 goto case State.ReadElementContentAsBase64;
1632 case State.ReadElementContentAsBase64:
1633 {
1635 if (num > 0 || count == 0)
1636 {
1637 return num;
1638 }
1639 if (NodeType != XmlNodeType.EndElement)
1640 {
1642 }
1643 _state = State.Interactive;
1645 if (reader.Depth != _initialDepth)
1646 {
1647 await ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
1648 }
1649 else
1650 {
1651 _state = State.EndOfFile;
1652 SetEmptyNode();
1653 }
1654 return 0;
1655 }
1656 case State.ReadElementContentAsBinHex:
1657 case State.ReadContentAsBase64:
1658 case State.ReadContentAsBinHex:
1660 default:
1661 return 0;
1662 }
1663 }
1664
1665 public override async Task<int> ReadContentAsBinHexAsync(byte[] buffer, int index, int count)
1666 {
1667 switch (_state)
1668 {
1669 case State.Initial:
1670 case State.Error:
1671 case State.EndOfFile:
1672 case State.Closed:
1673 return 0;
1674 case State.PopNamespaceScope:
1675 case State.ClearNsAttributes:
1676 switch (NodeType)
1677 {
1678 case XmlNodeType.Element:
1679 throw CreateReadContentAsException("ReadContentAsBinHex");
1680 case XmlNodeType.EndElement:
1681 return 0;
1682 case XmlNodeType.Attribute:
1684 {
1686 if (count == 0)
1687 {
1688 return 0;
1689 }
1690 if (_nsIncReadOffset == 0)
1691 {
1692 if (_binDecoder != null && _binDecoder is BinHexDecoder)
1693 {
1695 }
1696 else
1697 {
1698 _binDecoder = new BinHexDecoder();
1699 }
1700 }
1701 if (_nsIncReadOffset == _curNode.value.Length)
1702 {
1703 return 0;
1704 }
1708 }
1709 goto case XmlNodeType.Text;
1710 case XmlNodeType.Text:
1712 default:
1713 return 0;
1714 }
1715 case State.Interactive:
1716 _state = State.ReadContentAsBinHex;
1717 goto case State.ReadContentAsBinHex;
1718 case State.ReadContentAsBinHex:
1719 {
1721 if (num == 0)
1722 {
1723 _state = State.Interactive;
1725 }
1726 return num;
1727 }
1728 case State.ReadElementContentAsBase64:
1729 case State.ReadElementContentAsBinHex:
1730 case State.ReadContentAsBase64:
1732 default:
1733 return 0;
1734 }
1735 }
1736
1738 {
1739 switch (_state)
1740 {
1741 case State.Initial:
1742 case State.Error:
1743 case State.EndOfFile:
1744 case State.Closed:
1745 return 0;
1746 case State.Interactive:
1747 case State.PopNamespaceScope:
1748 case State.ClearNsAttributes:
1749 if (!(await InitReadElementContentAsBinaryAsync(State.ReadElementContentAsBinHex).ConfigureAwait(continueOnCapturedContext: false)))
1750 {
1751 return 0;
1752 }
1753 goto case State.ReadElementContentAsBinHex;
1754 case State.ReadElementContentAsBinHex:
1755 {
1757 if (num > 0 || count == 0)
1758 {
1759 return num;
1760 }
1761 if (NodeType != XmlNodeType.EndElement)
1762 {
1764 }
1765 _state = State.Interactive;
1767 if (reader.Depth != _initialDepth)
1768 {
1769 await ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
1770 }
1771 else
1772 {
1773 _state = State.EndOfFile;
1774 SetEmptyNode();
1775 }
1776 return 0;
1777 }
1778 case State.ReadElementContentAsBase64:
1779 case State.ReadContentAsBase64:
1780 case State.ReadContentAsBinHex:
1782 default:
1783 return 0;
1784 }
1785 }
1786
1787 public override Task<int> ReadValueChunkAsync(char[] buffer, int index, int count)
1788 {
1789 switch (_state)
1790 {
1791 case State.Initial:
1792 case State.Error:
1793 case State.EndOfFile:
1794 case State.Closed:
1796 case State.PopNamespaceScope:
1797 case State.ClearNsAttributes:
1798 if (_curNsAttr != -1 && reader.CanReadValueChunk)
1799 {
1802 if (num > count)
1803 {
1804 num = count;
1805 }
1806 if (num > 0)
1807 {
1809 }
1810 _nsIncReadOffset += num;
1811 return Task.FromResult(num);
1812 }
1813 goto case State.Interactive;
1814 case State.Interactive:
1816 case State.ReadElementContentAsBase64:
1817 case State.ReadElementContentAsBinHex:
1818 case State.ReadContentAsBase64:
1819 case State.ReadContentAsBinHex:
1821 default:
1823 }
1824 }
1825
1827 {
1828 if (NodeType != XmlNodeType.Element)
1829 {
1830 throw reader.CreateReadElementContentAsException("ReadElementContentAsBase64");
1831 }
1832 bool isEmpty = IsEmptyElement;
1833 if (!(await ReadAsync().ConfigureAwait(continueOnCapturedContext: false)) || isEmpty)
1834 {
1835 return false;
1836 }
1837 switch (NodeType)
1838 {
1839 case XmlNodeType.Element:
1841 case XmlNodeType.EndElement:
1843 await ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
1844 return false;
1845 default:
1847 return true;
1848 }
1849 }
1850
1852 {
1853 byte[] bytes = new byte[256];
1854 if (_state == State.ReadElementContentAsBase64)
1855 {
1856 while (await reader.ReadContentAsBase64Async(bytes, 0, 256).ConfigureAwait(continueOnCapturedContext: false) > 0)
1857 {
1858 }
1859 }
1860 else
1861 {
1862 while (await reader.ReadContentAsBinHexAsync(bytes, 0, 256).ConfigureAwait(continueOnCapturedContext: false) > 0)
1863 {
1864 }
1865 }
1866 if (NodeType != XmlNodeType.EndElement)
1867 {
1869 }
1870 _state = State.Interactive;
1872 if (reader.Depth == _initialDepth)
1873 {
1874 _state = State.EndOfFile;
1875 SetEmptyNode();
1876 return false;
1877 }
1878 return await ReadAsync().ConfigureAwait(continueOnCapturedContext: false);
1879 }
1880
1882 {
1883 byte[] bytes = new byte[256];
1884 if (_state == State.ReadContentAsBase64)
1885 {
1886 while (await reader.ReadContentAsBase64Async(bytes, 0, 256).ConfigureAwait(continueOnCapturedContext: false) > 0)
1887 {
1888 }
1889 }
1890 else
1891 {
1892 while (await reader.ReadContentAsBinHexAsync(bytes, 0, 256).ConfigureAwait(continueOnCapturedContext: false) > 0)
1893 {
1894 }
1895 }
1896 _state = State.Interactive;
1898 if (reader.Depth == _initialDepth)
1899 {
1900 _state = State.EndOfFile;
1901 SetEmptyNode();
1902 return false;
1903 }
1904 return true;
1905 }
1906}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static string Xml_ClosedOrErrorReader
Definition SR.cs:206
static string Xml_InvalidNodeType
Definition SR.cs:88
static string Xml_MixingBinaryContentMethods
Definition SR.cs:184
static string Xml_MixingReadValueChunkWithBinary
Definition SR.cs:182
Definition SR.cs:7
static readonly Task< int > DoneTaskZero
int Decode(char[] chars, int startPos, int len)
void SetNextOutputBuffer(Array array, int offset, int len)
static bool Equal(string strA, string strB)
Definition Ref.cs:5
string Add(char[] array, int offset, int length)
virtual ? string LookupNamespace(string prefix)
virtual ? string LookupPrefix(string uri)
virtual IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
virtual void AddNamespace(string prefix, string uri)
virtual string ReadContentAsString()
Definition XmlReader.cs:286
Exception CreateReadElementContentAsException(string methodName)
virtual long ReadContentAsLong()
Definition XmlReader.cs:270
string? GetAttribute(string name)
virtual void Skip()
Definition XmlReader.cs:532
virtual Task< int > ReadContentAsBinHexAsync(byte[] buffer, int index, int count)
virtual Task SkipAsync()
bool MoveToAttribute(string name)
Exception CreateReadContentAsException(string methodName)
virtual async Task< object > ReadContentAsObjectAsync()
virtual int ReadValueChunk(char[] buffer, int index, int count)
Definition XmlReader.cs:564
virtual int ReadContentAsBinHex(byte[] buffer, int index, int count)
Definition XmlReader.cs:554
virtual float ReadContentAsFloat()
Definition XmlReader.cs:222
virtual int ReadContentAsInt()
Definition XmlReader.cs:254
virtual bool ReadContentAsBoolean()
Definition XmlReader.cs:158
virtual Task< int > ReadValueChunkAsync(char[] buffer, int index, int count)
virtual Task< bool > ReadAsync()
virtual decimal ReadContentAsDecimal()
Definition XmlReader.cs:238
virtual object ReadContentAsObject()
Definition XmlReader.cs:149
virtual double ReadContentAsDouble()
Definition XmlReader.cs:206
virtual DateTime ReadContentAsDateTime()
Definition XmlReader.cs:174
virtual Task< string > ReadContentAsStringAsync()
virtual Task< int > ReadContentAsBase64Async(byte[] buffer, int index, int count)
virtual int ReadContentAsBase64(byte[] buffer, int index, int count)
Definition XmlReader.cs:544
XmlNodeType NodeType
Definition XmlReader.cs:62
virtual object ReadContentAs(Type returnType, IXmlNamespaceResolver? namespaceResolver)
Definition XmlReader.cs:295
XmlNameTable NameTable
Definition XmlReader.cs:116
virtual async Task< object > ReadContentAsAsync(Type returnType, IXmlNamespaceResolver? namespaceResolver)
virtual Task< string > GetValueAsync()
virtual string Name
Definition XmlReader.cs:65
virtual bool CanReadValueChunk
Definition XmlReader.cs:122
virtual bool CanReadBinaryContent
Definition XmlReader.cs:120
void Set(XmlNodeType nodeType, string localName, string prefix, string name, string namespaceUri, string value)
NodeData(XmlNodeType nodeType, string localName, string prefix, string name, string namespaceUri, string value)
XmlSubtreeReader(XmlReader reader)
override bool MoveToAttribute(string name)
override async Task< bool > ReadAsync()
override string GetAttribute(string name, string namespaceURI)
override string GetAttribute(string name)
override async Task< int > ReadContentAsBinHexAsync(byte[] buffer, int index, int count)
override bool MoveToAttribute(string name, string ns)
readonly XmlNamespaceManager _nsManager
override decimal ReadContentAsDecimal()
async Task< bool > FinishReadContentAsBinaryAsync()
override int ReadValueChunk(char[] buffer, int index, int count)
async Task< bool > InitReadElementContentAsBinaryAsync(State binaryState)
bool InitReadElementContentAsBinary(State binaryState)
override string GetAttribute(int i)
override DateTime ReadContentAsDateTime()
override async Task< string > ReadContentAsStringAsync()
override object ReadContentAs(Type returnType, IXmlNamespaceResolver namespaceResolver)
override int ReadElementContentAsBase64(byte[] buffer, int index, int count)
void InitReadContentAsType(string methodName)
override void Dispose(bool disposing)
override object ReadContentAsObject()
override async Task SkipAsync()
override async Task< int > ReadElementContentAsBase64Async(byte[] buffer, int index, int count)
void SetCurrentNode(NodeData node)
override string ReadContentAsString()
IncrementalReadDecoder _binDecoder
override async Task< object > ReadContentAsObjectAsync()
override async Task< int > ReadElementContentAsBinHexAsync(byte[] buffer, int index, int count)
override async Task< int > ReadContentAsBase64Async(byte[] buffer, int index, int count)
override void MoveToAttribute(int i)
override string LookupNamespace(string prefix)
override int ReadContentAsBase64(byte[] buffer, int index, int count)
override Task< int > ReadValueChunkAsync(char[] buffer, int index, int count)
async Task< bool > FinishReadElementContentAsBinaryAsync()
override Task< string > GetValueAsync()
void CheckBuffer(Array buffer, int index, int count)
void AddNamespace(string prefix, string ns)
override XmlNodeType NodeType
override int ReadElementContentAsBinHex(byte[] buffer, int index, int count)
override async Task< object > ReadContentAsAsync(Type returnType, IXmlNamespaceResolver namespaceResolver)
void RemoveNamespace(string prefix, string localName)
override double ReadContentAsDouble()
override float ReadContentAsFloat()
override int ReadContentAsBinHex(byte[] buffer, int index, int count)
IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
string? LookupPrefix(string namespaceName)
string? LookupNamespace(string prefix)