Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlReaderDelegator.cs
Go to the documentation of this file.
4using System.Xml;
6
8
9internal class XmlReaderDelegator
10{
11 protected XmlReader reader;
12
14
15 protected bool isEndOfEmptyElement;
16
18
20
21 internal int AttributeCount
22 {
23 get
24 {
26 {
28 }
29 return 0;
30 }
31 }
32
33 internal bool IsEmptyElement => false;
34
36 {
37 get
38 {
40 {
41 return reader.NodeType;
42 }
43 return XmlNodeType.EndElement;
44 }
45 }
46
47 internal int LineNumber
48 {
49 get
50 {
52 {
53 return xmlLineInfo.LineNumber;
54 }
55 return 0;
56 }
57 }
58
59 internal int LinePosition
60 {
61 get
62 {
64 {
65 return xmlLineInfo.LinePosition;
66 }
67 return 0;
68 }
69 }
70
71 internal bool Normalized
72 {
73 get
74 {
76 {
78 {
79 return xmlTextParser.Normalized;
80 }
81 return false;
82 }
83 return xmlTextReader.Normalization;
84 }
85 set
86 {
88 {
90 {
92 }
93 }
94 else
95 {
97 }
98 }
99 }
100
102 {
103 get
104 {
106 {
108 {
109 return xmlTextParser.WhitespaceHandling;
110 }
111 return WhitespaceHandling.None;
112 }
113 return xmlTextReader.WhitespaceHandling;
114 }
115 set
116 {
118 {
120 {
122 }
123 }
124 else
125 {
127 }
128 }
129 }
130
131 internal string Name => reader.Name;
132
133 internal string LocalName => reader.LocalName;
134
135 internal string NamespaceURI => reader.NamespaceURI;
136
137 internal string Value => reader.Value;
138
140
141 internal int Depth => reader.Depth;
142
143 internal bool EOF => reader.EOF;
144
151
152 internal string GetAttribute(string name)
153 {
155 {
156 return reader.GetAttribute(name);
157 }
158 return null;
159 }
160
161 internal string GetAttribute(string name, string namespaceUri)
162 {
164 {
165 return reader.GetAttribute(name, namespaceUri);
166 }
167 return null;
168 }
169
170 internal string GetAttribute(int i)
171 {
173 {
175 }
176 return reader.GetAttribute(i);
177 }
178
179 internal bool IsNamespaceURI(string ns)
180 {
181 if (dictionaryReader == null)
182 {
183 return ns == reader.NamespaceURI;
184 }
186 }
187
188 internal bool IsLocalName(string localName)
189 {
190 if (dictionaryReader == null)
191 {
192 return localName == reader.LocalName;
193 }
194 return dictionaryReader.IsLocalName(localName);
195 }
196
198 {
199 if (dictionaryReader == null)
200 {
201 return ns.Value == reader.NamespaceURI;
202 }
204 }
205
206 internal bool IsLocalName(XmlDictionaryString localName)
207 {
208 if (dictionaryReader == null)
209 {
211 }
212 return dictionaryReader.IsLocalName(localName);
213 }
214
216 {
217 if (dictionaryReader != null)
218 {
220 }
221 if (reader.NamespaceURI == ns.Value)
222 {
223 string localName = LocalName;
224 for (int i = 0; i < localNames.Length; i++)
225 {
226 if (localName == localNames[i].Value)
227 {
228 return i;
229 }
230 }
231 }
232 return -1;
233 }
234
235 internal bool IsStartElement()
236 {
238 {
239 return reader.IsStartElement();
240 }
241 return false;
242 }
243
244 internal bool IsStartElement(string localname, string ns)
245 {
247 {
248 return reader.IsStartElement(localname, ns);
249 }
250 return false;
251 }
252
254 {
255 if (dictionaryReader == null)
256 {
258 {
259 return reader.IsStartElement(localname.Value, ns.Value);
260 }
261 return false;
262 }
264 {
265 return dictionaryReader.IsStartElement(localname, ns);
266 }
267 return false;
268 }
269
270 internal bool MoveToAttribute(string name)
271 {
273 {
274 return reader.MoveToAttribute(name);
275 }
276 return false;
277 }
278
279 internal bool MoveToAttribute(string name, string ns)
280 {
282 {
283 return reader.MoveToAttribute(name, ns);
284 }
285 return false;
286 }
287
296
297 internal bool MoveToElement()
298 {
300 {
301 return reader.MoveToElement();
302 }
303 return false;
304 }
305
306 internal bool MoveToFirstAttribute()
307 {
309 {
311 }
312 return false;
313 }
314
315 internal bool MoveToNextAttribute()
316 {
318 {
320 }
321 return false;
322 }
323
324 internal bool Read()
325 {
328 {
329 return reader.Read();
330 }
332 {
333 isEndOfEmptyElement = false;
334 return reader.Read();
335 }
336 isEndOfEmptyElement = true;
337 return true;
338 }
339
341 {
343 {
344 return XmlNodeType.EndElement;
345 }
346 return reader.MoveToContent();
347 }
348
349 internal bool ReadAttributeValue()
350 {
352 {
353 return reader.ReadAttributeValue();
354 }
355 return false;
356 }
357
358 internal void ReadEndElement()
359 {
361 {
362 Read();
363 }
364 else
365 {
367 }
368 }
369
374
376 {
377 Read();
378 object result = ReadContentAsAnyType(valueType);
380 return result;
381 }
382
384 {
385 switch (Type.GetTypeCode(valueType))
386 {
387 case TypeCode.Boolean:
388 return ReadContentAsBoolean();
389 case TypeCode.Char:
390 return ReadContentAsChar();
391 case TypeCode.Byte:
393 case TypeCode.Int16:
394 return ReadContentAsShort();
395 case TypeCode.Int32:
396 return ReadContentAsInt();
397 case TypeCode.Int64:
398 return ReadContentAsLong();
399 case TypeCode.Single:
400 return ReadContentAsSingle();
401 case TypeCode.Double:
402 return ReadContentAsDouble();
403 case TypeCode.Decimal:
404 return ReadContentAsDecimal();
405 case TypeCode.DateTime:
406 return ReadContentAsDateTime();
407 case TypeCode.String:
408 return ReadContentAsString();
409 case TypeCode.SByte:
411 case TypeCode.UInt16:
413 case TypeCode.UInt32:
415 case TypeCode.UInt64:
417 default:
419 {
420 return ReadContentAsBase64();
421 }
423 {
424 return new object();
425 }
427 {
428 return ReadContentAsTimeSpan();
429 }
431 {
432 return ReadContentAsGuid();
433 }
435 {
436 return ReadContentAsUri();
437 }
439 {
440 return ReadContentAsQName();
441 }
443 }
444 }
445
447 {
448 switch (Type.GetTypeCode(valueType))
449 {
450 case TypeCode.Boolean:
452 case TypeCode.Char:
453 return new DataNode<char>(ReadContentAsChar());
454 case TypeCode.Byte:
456 case TypeCode.Int16:
458 case TypeCode.Int32:
459 return new DataNode<int>(ReadContentAsInt());
460 case TypeCode.Int64:
461 return new DataNode<long>(ReadContentAsLong());
462 case TypeCode.Single:
464 case TypeCode.Double:
466 case TypeCode.Decimal:
468 case TypeCode.DateTime:
470 case TypeCode.String:
472 case TypeCode.SByte:
474 case TypeCode.UInt16:
476 case TypeCode.UInt32:
478 case TypeCode.UInt64:
480 default:
482 {
484 }
486 {
487 return new DataNode<object>(new object());
488 }
490 {
492 }
494 {
495 return new DataNode<Guid>(ReadContentAsGuid());
496 }
498 {
499 return new DataNode<Uri>(ReadContentAsUri());
500 }
502 {
504 }
506 }
507 }
508
514
520
521 internal virtual char ReadElementContentAsChar()
522 {
524 }
525
526 internal virtual char ReadContentAsChar()
527 {
528 return ToChar(ReadContentAsInt());
529 }
530
531 private char ToChar(int value)
532 {
533 if (value < 0 || value > 65535)
534 {
536 }
537 return (char)value;
538 }
539
541 {
543 {
545 }
547 }
548
549 internal string ReadContentAsString()
550 {
552 {
554 }
555 return string.Empty;
556 }
557
559 {
561 {
563 }
565 }
566
567 internal bool ReadContentAsBoolean()
568 {
570 {
571 ThrowConversionException(string.Empty, "Boolean");
572 }
574 }
575
577 {
579 {
581 }
583 }
584
585 internal float ReadContentAsSingle()
586 {
588 {
589 ThrowConversionException(string.Empty, "Float");
590 }
591 return reader.ReadContentAsFloat();
592 }
593
595 {
597 {
599 }
601 }
602
603 internal double ReadContentAsDouble()
604 {
606 {
607 ThrowConversionException(string.Empty, "Double");
608 }
610 }
611
613 {
615 {
617 }
619 }
620
621 internal decimal ReadContentAsDecimal()
622 {
624 {
625 ThrowConversionException(string.Empty, "Decimal");
626 }
628 }
629
630 internal virtual byte[] ReadElementContentAsBase64()
631 {
633 {
635 }
636 if (dictionaryReader == null)
637 {
639 }
641 }
642
643 public virtual byte[] ReadContentAsBase64()
644 {
646 {
647 return Array.Empty<byte>();
648 }
649 if (dictionaryReader == null)
650 {
652 }
654 }
655
656 [return: NotNullIfNotNull("str")]
657 internal byte[] ReadContentAsBase64(string str)
658 {
659 if (str == null)
660 {
661 return null;
662 }
663 str = str.Trim();
664 if (str.Length == 0)
665 {
666 return Array.Empty<byte>();
667 }
668 try
669 {
671 }
673 {
675 }
677 {
679 }
680 }
681
690
692 {
694 {
695 ThrowConversionException(string.Empty, "DateTime");
696 }
698 }
699
701 {
703 {
705 }
707 }
708
709 internal int ReadContentAsInt()
710 {
712 {
713 ThrowConversionException(string.Empty, "Int32");
714 }
715 return reader.ReadContentAsInt();
716 }
717
719 {
721 {
723 }
725 }
726
727 internal long ReadContentAsLong()
728 {
730 {
731 ThrowConversionException(string.Empty, "Int64");
732 }
733 return reader.ReadContentAsLong();
734 }
735
737 {
739 }
740
741 internal short ReadContentAsShort()
742 {
743 return ToShort(ReadContentAsInt());
744 }
745
746 private short ToShort(int value)
747 {
749 {
751 }
752 return (short)value;
753 }
754
756 {
758 }
759
761 {
762 return ToByte(ReadContentAsInt());
763 }
764
765 private byte ToByte(int value)
766 {
767 if (value < 0 || value > 255)
768 {
770 }
771 return (byte)value;
772 }
773
775 {
777 }
778
779 internal sbyte ReadContentAsSignedByte()
780 {
781 return ToSByte(ReadContentAsInt());
782 }
783
784 private sbyte ToSByte(int value)
785 {
787 {
789 }
790 return (sbyte)value;
791 }
792
794 {
796 }
797
799 {
800 return ToUInt32(ReadContentAsLong());
801 }
802
803 private uint ToUInt32(long value)
804 {
805 if (value < 0 || value > uint.MaxValue)
806 {
808 }
809 return (uint)value;
810 }
811
812 internal virtual ulong ReadElementContentAsUnsignedLong()
813 {
815 {
817 }
819 if (text == null || text.Length == 0)
820 {
821 ThrowConversionException(string.Empty, "UInt64");
822 }
823 return XmlConverter.ToUInt64(text);
824 }
825
826 internal virtual ulong ReadContentAsUnsignedLong()
827 {
829 if (text == null || text.Length == 0)
830 {
831 ThrowConversionException(string.Empty, "UInt64");
832 }
833 return XmlConverter.ToUInt64(text);
834 }
835
837 {
839 }
840
842 {
843 return ToUInt16(ReadContentAsInt());
844 }
845
846 private ushort ToUInt16(int value)
847 {
848 if (value < 0 || value > 65535)
849 {
851 }
852 return (ushort)value;
853 }
854
864
866 {
869 }
870
895
916
937
954
956 {
957 Read();
960 return result;
961 }
962
964 {
966 }
967
969 {
970 string name;
971 string ns;
972 if (str == null || str.Length == 0)
973 {
974 name = (ns = string.Empty);
975 }
976 else
977 {
979 }
980 return new XmlQualifiedName(name, ns);
981 }
982
987
989 {
990 return Math.Min(context.RemainingItemCount, int.MaxValue);
991 }
992
1000
1002 {
1003 if (dictionaryReader == null)
1004 {
1005 array = null;
1006 return false;
1007 }
1008 if (arrayLength != -1)
1009 {
1011 array = new bool[arrayLength];
1012 int num = 0;
1013 int num2 = 0;
1015 {
1016 num2 += num;
1017 }
1019 }
1020 else
1021 {
1023 context.IncrementItemCount(array.Length);
1024 }
1025 return true;
1026 }
1027
1029 {
1030 if (dictionaryReader == null)
1031 {
1032 array = null;
1033 return false;
1034 }
1035 if (arrayLength != -1)
1036 {
1038 array = new DateTime[arrayLength];
1039 int num = 0;
1040 int num2 = 0;
1042 {
1043 num2 += num;
1044 }
1046 }
1047 else
1048 {
1050 context.IncrementItemCount(array.Length);
1051 }
1052 return true;
1053 }
1054
1056 {
1057 if (dictionaryReader == null)
1058 {
1059 array = null;
1060 return false;
1061 }
1062 if (arrayLength != -1)
1063 {
1065 array = new decimal[arrayLength];
1066 int num = 0;
1067 int num2 = 0;
1069 {
1070 num2 += num;
1071 }
1073 }
1074 else
1075 {
1077 context.IncrementItemCount(array.Length);
1078 }
1079 return true;
1080 }
1081
1083 {
1084 if (dictionaryReader == null)
1085 {
1086 array = null;
1087 return false;
1088 }
1089 if (arrayLength != -1)
1090 {
1092 array = new int[arrayLength];
1093 int num = 0;
1094 int num2 = 0;
1096 {
1097 num2 += num;
1098 }
1100 }
1101 else
1102 {
1104 context.IncrementItemCount(array.Length);
1105 }
1106 return true;
1107 }
1108
1110 {
1111 if (dictionaryReader == null)
1112 {
1113 array = null;
1114 return false;
1115 }
1116 if (arrayLength != -1)
1117 {
1119 array = new long[arrayLength];
1120 int num = 0;
1121 int num2 = 0;
1123 {
1124 num2 += num;
1125 }
1127 }
1128 else
1129 {
1131 context.IncrementItemCount(array.Length);
1132 }
1133 return true;
1134 }
1135
1137 {
1138 if (dictionaryReader == null)
1139 {
1140 array = null;
1141 return false;
1142 }
1143 if (arrayLength != -1)
1144 {
1146 array = new float[arrayLength];
1147 int num = 0;
1148 int num2 = 0;
1150 {
1151 num2 += num;
1152 }
1154 }
1155 else
1156 {
1158 context.IncrementItemCount(array.Length);
1159 }
1160 return true;
1161 }
1162
1164 {
1165 if (dictionaryReader == null)
1166 {
1167 array = null;
1168 return false;
1169 }
1170 if (arrayLength != -1)
1171 {
1173 array = new double[arrayLength];
1174 int num = 0;
1175 int num2 = 0;
1177 {
1178 num2 += num;
1179 }
1181 }
1182 else
1183 {
1185 context.IncrementItemCount(array.Length);
1186 }
1187 return true;
1188 }
1189
1191 {
1193 {
1194 return null;
1195 }
1196 return ((IXmlNamespaceResolver)reader).GetNamespacesInScope(scope);
1197 }
1198
1199 internal bool HasLineInfo()
1200 {
1202 {
1203 return xmlLineInfo.HasLineInfo();
1204 }
1205 return false;
1206 }
1207
1208 internal string LookupNamespace(string prefix)
1209 {
1211 }
1212
1213 internal void Skip()
1214 {
1215 reader.Skip();
1216 isEndOfEmptyElement = false;
1217 }
1218}
static unsafe byte[] FromBase64String(string s)
Definition Convert.cs:2904
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static string GetClrTypeFullName(Type type)
static void ParseQualifiedName(string qname, XmlReaderDelegator xmlReader, out string name, out string ns, out string prefix)
static string TryAddLineInfo(XmlReaderDelegator reader, string errorMessage)
static SerializationException CreateSerializationException(string errorMessage)
static void CheckNull(object obj, string name)
bool IsLocalName(XmlDictionaryString localName)
string GetAttribute(string name, string namespaceUri)
bool TryReadInt32Array(XmlObjectSerializerReadContext context, XmlDictionaryString itemName, XmlDictionaryString itemNamespace, int arrayLength, [NotNullWhen(true)] out int[] array)
virtual bool TryReadDateTimeArray(XmlObjectSerializerReadContext context, XmlDictionaryString itemName, XmlDictionaryString itemNamespace, int arrayLength, [NotNullWhen(true)] out DateTime[] array)
void CheckExpectedArrayLength(XmlObjectSerializerReadContext context, int arrayLength)
bool IsStartElement(string localname, string ns)
bool TryReadInt64Array(XmlObjectSerializerReadContext context, XmlDictionaryString itemName, XmlDictionaryString itemNamespace, int arrayLength, [NotNullWhen(true)] out long[] array)
void CheckActualArrayLength(int expectedLength, int actualLength, XmlDictionaryString itemName, XmlDictionaryString itemNamespace)
bool TryReadDoubleArray(XmlObjectSerializerReadContext context, XmlDictionaryString itemName, XmlDictionaryString itemNamespace, int arrayLength, [NotNullWhen(true)] out double[] array)
void ThrowConversionException(string value, string type)
bool TryReadBooleanArray(XmlObjectSerializerReadContext context, XmlDictionaryString itemName, XmlDictionaryString itemNamespace, int arrayLength, [NotNullWhen(true)] out bool[] array)
IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
int IndexOfLocalName(XmlDictionaryString[] localNames, XmlDictionaryString ns)
bool TryReadSingleArray(XmlObjectSerializerReadContext context, XmlDictionaryString itemName, XmlDictionaryString itemNamespace, int arrayLength, [NotNullWhen(true)] out float[] array)
bool IsStartElement(XmlDictionaryString localname, XmlDictionaryString ns)
bool TryReadDecimalArray(XmlObjectSerializerReadContext context, XmlDictionaryString itemName, XmlDictionaryString itemNamespace, int arrayLength, [NotNullWhen(true)] out decimal[] array)
int GetArrayLengthQuota(XmlObjectSerializerReadContext context)
static string XmlElementAttributes
Definition SR.cs:308
static string XmlInvalidConversion
Definition SR.cs:312
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InterfaceTypeCannotBeCreated
Definition SR.cs:666
static string ArrayExceededSizeAttribute
Definition SR.cs:16
static string InvalidPrimitiveType_Serialization
Definition SR.cs:158
static string XmlStartElementExpected
Definition SR.cs:316
Definition SR.cs:7
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
static readonly BooleanArrayHelperWithDictionaryString Instance
static readonly DateTimeArrayHelperWithDictionaryString Instance
static readonly DecimalArrayHelperWithDictionaryString Instance
static readonly DoubleArrayHelperWithDictionaryString Instance
static readonly Int32ArrayHelperWithDictionaryString Instance
static readonly Int64ArrayHelperWithDictionaryString Instance
static readonly SingleArrayHelperWithDictionaryString Instance
static DateTime ToDateTime(string s)
static TimeSpan ToTimeSpan(string value)
static ulong ToUInt64(string value)
virtual bool IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
virtual bool IsLocalName(string localName)
virtual int IndexOfLocalName(string[] localNames, string namespaceUri)
virtual bool IsNamespaceUri(string namespaceUri)
virtual int ReadArray(string localName, string namespaceUri, bool[] array, int offset, int count)
static XmlException CreateConversionException(string type, Exception exception)
virtual string ReadContentAsString()
Definition XmlReader.cs:286
virtual Type ValueType
Definition XmlReader.cs:102
virtual long ReadContentAsLong()
Definition XmlReader.cs:270
string? GetAttribute(string name)
virtual void Skip()
Definition XmlReader.cs:532
virtual bool IsStartElement()
Definition XmlReader.cs:760
virtual long ReadElementContentAsLong()
Definition XmlReader.cs:439
virtual double ReadElementContentAsDouble()
Definition XmlReader.cs:371
virtual void ReadEndElement()
Definition XmlReader.cs:751
bool MoveToAttribute(string name)
virtual float ReadContentAsFloat()
Definition XmlReader.cs:222
virtual int ReadContentAsInt()
Definition XmlReader.cs:254
virtual bool ReadContentAsBoolean()
Definition XmlReader.cs:158
virtual decimal ReadContentAsDecimal()
Definition XmlReader.cs:238
string? LookupNamespace(string prefix)
virtual double ReadContentAsDouble()
Definition XmlReader.cs:206
virtual DateTime ReadContentAsDateTime()
Definition XmlReader.cs:174
virtual int ReadElementContentAsInt()
Definition XmlReader.cs:422
virtual XmlNodeType MoveToContent()
Definition XmlReader.cs:604
XmlNodeType NodeType
Definition XmlReader.cs:62
virtual float ReadElementContentAsFloat()
Definition XmlReader.cs:388
virtual decimal ReadElementContentAsDecimal()
Definition XmlReader.cs:405
virtual bool ReadElementContentAsBoolean()
Definition XmlReader.cs:337
virtual string Name
Definition XmlReader.cs:65
virtual string ReadElementContentAsString()
Definition XmlReader.cs:456
TypeCode
Definition TypeCode.cs:4
UriKind
Definition UriKind.cs:4
static Guid Parse(string input)
Definition Guid.cs:190