Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlSqlBinaryReader.cs
Go to the documentation of this file.
5using System.IO;
7using System.Text;
9
10namespace System.Xml;
11
13{
14 private enum ScanState
15 {
16 Doc,
17 XmlText,
18 Attr,
19 AttrVal,
21 Init,
22 Error,
23 EOF,
24 Closed
25 }
26
27 internal struct QName
28 {
29 public string prefix;
30
31 public string localname;
32
33 public string namespaceUri;
34
35 public QName(string prefix, string lname, string nsUri)
36 {
39 namespaceUri = nsUri;
40 }
41
42 public void Set(string prefix, string lname, string nsUri)
43 {
46 namespaceUri = nsUri;
47 }
48
49 public void Clear()
50 {
51 prefix = (localname = (namespaceUri = string.Empty));
52 }
53
54 public bool MatchNs(string lname, string nsUri)
55 {
56 if (lname == localname)
57 {
58 return nsUri == namespaceUri;
59 }
60 return false;
61 }
62
63 public bool MatchPrefix(string prefix, string lname)
64 {
65 if (lname == localname)
66 {
67 return prefix == this.prefix;
68 }
69 return false;
70 }
71
72 public void CheckPrefixNS(string prefix, string namespaceUri)
73 {
74 if (this.prefix == prefix && this.namespaceUri != namespaceUri)
75 {
76 throw new XmlException(System.SR.XmlBinary_NoRemapPrefix, new string[3] { prefix, this.namespaceUri, namespaceUri });
77 }
78 }
79
80 public override int GetHashCode()
81 {
82 return prefix.GetHashCode() ^ localname.GetHashCode();
83 }
84
85 public int GetNSHashCode()
86 {
87 return HashCode.Combine(namespaceUri, localname);
88 }
89
90 public override bool Equals([NotNullWhen(true)] object other)
91 {
92 if (other is QName qName)
93 {
94 return this == qName;
95 }
96 return false;
97 }
98
99 public override string ToString()
100 {
101 if (prefix.Length == 0)
102 {
103 return localname;
104 }
105 return prefix + ":" + localname;
106 }
107
108 public static bool operator ==(QName a, QName b)
109 {
110 if (a.prefix == b.prefix && a.localname == b.localname)
111 {
112 return a.namespaceUri == b.namespaceUri;
113 }
114 return false;
115 }
116
117 public static bool operator !=(QName a, QName b)
118 {
119 return !(a == b);
120 }
121 }
122
123 private struct ElemInfo
124 {
125 public QName name;
126
127 public string xmlLang;
128
130
131 public bool xmlspacePreserve;
132
134
135 public void Set(QName name, bool xmlspacePreserve)
136 {
137 this.name = name;
138 xmlLang = null;
139 xmlSpace = XmlSpace.None;
141 }
142
144 {
145 NamespaceDecl result = nsdecls;
146 nsdecls = null;
147 return result;
148 }
149 }
150
151 private struct AttrInfo
152 {
153 public QName name;
154
155 public string val;
156
157 public int contentPos;
158
159 public int hashCode;
160
161 public int prevHash;
162
163 public void Set(QName n, string v)
164 {
165 name = n;
166 val = v;
167 contentPos = 0;
168 hashCode = 0;
169 prevHash = 0;
170 }
171
172 public void Set(QName n, int pos)
173 {
174 name = n;
175 val = null;
176 contentPos = pos;
177 hashCode = 0;
178 prevHash = 0;
179 }
180
181 public void GetLocalnameAndNamespaceUri(out string localname, out string namespaceUri)
182 {
183 localname = name.localname;
184 namespaceUri = name.namespaceUri;
185 }
186
187 public int GetLocalnameAndNamespaceUriAndHash(out string localname, out string namespaceUri)
188 {
189 localname = name.localname;
190 namespaceUri = name.namespaceUri;
191 return hashCode = name.GetNSHashCode();
192 }
193
194 public bool MatchNS(string localname, string namespaceUri)
195 {
196 return name.MatchNs(localname, namespaceUri);
197 }
198
199 public bool MatchHashNS(int hash, string localname, string namespaceUri)
200 {
201 if (hashCode == hash)
202 {
203 return name.MatchNs(localname, namespaceUri);
204 }
205 return false;
206 }
207
208 public void AdjustPosition(int adj)
209 {
210 if (contentPos != 0)
211 {
212 contentPos += adj;
213 }
214 }
215 }
216
217 private sealed class NamespaceDecl
218 {
219 public string prefix;
220
221 public string uri;
222
224
226
227 public int scope;
228
229 public bool implied;
230
240 }
241
242 private struct SymbolTables
243 {
244 public string[] symtable;
245
246 public int symCount;
247
249
250 public int qnameCount;
251
252 public void Init()
253 {
254 symtable = new string[64];
255 qnametable = new QName[16];
256 symtable[0] = string.Empty;
257 symCount = 1;
258 qnameCount = 1;
259 }
260 }
261
262 private sealed class NestedBinXml
263 {
265
266 public int docState;
267
269
276 }
277
278 internal static readonly Type TypeOfObject = typeof(object);
279
280 internal static readonly Type TypeOfString = typeof(string);
281
282 private static volatile Type[] s_tokenTypeMap = null;
283
284 private static readonly ReadState[] s_scanState2ReadState = new ReadState[9]
285 {
286 ReadState.Interactive,
287 ReadState.Interactive,
288 ReadState.Interactive,
289 ReadState.Interactive,
290 ReadState.Interactive,
291 ReadState.Initial,
292 ReadState.Error,
293 ReadState.EndOfFile,
295 };
296
298
299 private byte[] _data;
300
301 private int _pos;
302
303 private int _mark;
304
305 private int _end;
306
307 private bool _eof;
308
309 private bool _sniffed;
310
311 private bool _isEmpty;
312
313 private int _docState;
314
316
317 private readonly XmlNameTable _xnt;
318
319 private readonly bool _xntFromSettings;
320
321 private readonly string _xml;
322
323 private readonly string _xmlns;
324
325 private readonly string _nsxmlns;
326
327 private readonly string _baseUri;
328
330
332
334
335 private int _attrIndex;
336
338
340
342
344
345 private int _elemDepth;
346
348
349 private int[] _attrHashTbl;
350
351 private int _attrCount;
352
353 private int _posAfterAttrs;
354
355 private bool _xmlspacePreserve;
356
357 private int _tokLen;
358
359 private int _tokDataPos;
360
361 private bool _hasTypedValue;
362
364
365 private string _stringValue;
366
368
370
372
373 private readonly bool _closeInput;
374
375 private readonly bool _checkCharacters;
376
377 private readonly bool _ignoreWhitespace;
378
379 private readonly bool _ignorePIs;
380
381 private readonly bool _ignoreComments;
382
384
385 private byte _version;
386
387 private static ReadOnlySpan<byte> XsdKatmaiTimeScaleToValueLengthMap => new byte[8] { 3, 3, 3, 4, 4, 5, 5, 5 };
388
415
416 public override XmlNodeType NodeType => _nodetype;
417
418 public override string LocalName => _qnameOther.localname;
419
420 public override string NamespaceURI => _qnameOther.namespaceUri;
421
422 public override string Prefix => _qnameOther.prefix;
423
424 public override bool HasValue
425 {
426 get
427 {
428 if (ScanState.XmlText == _state)
429 {
431 }
433 }
434 }
435
436 public override string Value
437 {
438 get
439 {
440 if (_stringValue != null)
441 {
442 return _stringValue;
443 }
444 switch (_state)
445 {
446 case ScanState.Doc:
447 switch (_nodetype)
448 {
449 case XmlNodeType.ProcessingInstruction:
450 case XmlNodeType.Comment:
451 case XmlNodeType.DocumentType:
453 case XmlNodeType.CDATA:
454 return _stringValue = CDATAValue();
455 case XmlNodeType.XmlDeclaration:
456 return _stringValue = XmlDeclValue();
457 case XmlNodeType.Text:
458 case XmlNodeType.Whitespace:
459 case XmlNodeType.SignificantWhitespace:
461 }
462 break;
463 case ScanState.XmlText:
464 return _textXmlReader.Value;
465 case ScanState.Attr:
466 case ScanState.AttrValPseudoValue:
468 case ScanState.AttrVal:
470 }
471 return string.Empty;
472 }
473 }
474
475 public override int Depth
476 {
477 get
478 {
479 int num = 0;
480 switch (_state)
481 {
482 case ScanState.Doc:
483 if (_nodetype == XmlNodeType.Element || _nodetype == XmlNodeType.EndElement)
484 {
485 num = -1;
486 }
487 break;
488 case ScanState.XmlText:
489 num = _textXmlReader.Depth;
490 break;
491 case ScanState.Attr:
492 if (_parentNodeType != XmlNodeType.Element)
493 {
494 num = 1;
495 }
496 break;
497 case ScanState.AttrVal:
498 case ScanState.AttrValPseudoValue:
499 if (_parentNodeType != XmlNodeType.Element)
500 {
501 num = 1;
502 }
503 num++;
504 break;
505 default:
506 return 0;
507 }
508 return _elemDepth + num;
509 }
510 }
511
512 public override string BaseURI => _baseUri;
513
514 public override bool IsEmptyElement
515 {
516 get
517 {
519 if ((uint)state <= 1u)
520 {
521 return _isEmpty;
522 }
523 return false;
524 }
525 }
526
527 public override XmlSpace XmlSpace
528 {
529 get
530 {
531 if (ScanState.XmlText != _state)
532 {
533 for (int num = _elemDepth; num >= 0; num--)
534 {
535 XmlSpace xmlSpace = _elementStack[num].xmlSpace;
536 if (xmlSpace != 0)
537 {
538 return xmlSpace;
539 }
540 }
541 return XmlSpace.None;
542 }
544 }
545 }
546
547 public override string XmlLang
548 {
549 get
550 {
551 if (ScanState.XmlText != _state)
552 {
553 for (int num = _elemDepth; num >= 0; num--)
554 {
555 string xmlLang = _elementStack[num].xmlLang;
556 if (xmlLang != null)
557 {
558 return xmlLang;
559 }
560 }
561 return string.Empty;
562 }
563 return _textXmlReader.XmlLang;
564 }
565 }
566
567 public override Type ValueType => _valueType;
568
569 public override int AttributeCount
570 {
571 get
572 {
573 switch (_state)
574 {
575 case ScanState.Doc:
576 case ScanState.Attr:
577 case ScanState.AttrVal:
578 case ScanState.AttrValPseudoValue:
579 return _attrCount;
580 case ScanState.XmlText:
582 default:
583 return 0;
584 }
585 }
586 }
587
588 public override bool EOF => _state == ScanState.EOF;
589
590 public override XmlNameTable NameTable => _xnt;
591
593
594 public XmlSqlBinaryReader(Stream stream, byte[] data, int len, string baseUri, bool closeInput, XmlReaderSettings settings)
595 {
596 _xnt = settings.NameTable;
597 if (_xnt == null)
598 {
599 _xnt = new NameTable();
600 _xntFromSettings = false;
601 }
602 else
603 {
604 _xntFromSettings = true;
605 }
606 _xml = _xnt.Add("xml");
607 _xmlns = _xnt.Add("xmlns");
608 _nsxmlns = _xnt.Add("http://www.w3.org/2000/xmlns/");
609 _baseUri = baseUri;
610 _state = ScanState.Init;
611 _nodetype = XmlNodeType.None;
612 _token = BinXmlToken.Error;
613 _elementStack = new ElemInfo[16];
614 _attributes = new AttrInfo[8];
615 _attrHashTbl = new int[8];
619 _xmlspacePreserve = false;
621 AddInitNamespace(string.Empty, string.Empty);
622 AddInitNamespace(_xml, _xnt.Add("http://www.w3.org/XML/1998/namespace"));
625 _inStrm = stream;
626 if (data != null)
627 {
628 _data = data;
629 _end = len;
630 _pos = 2;
631 _sniffed = true;
632 }
633 else
634 {
635 _data = new byte[4096];
636 _end = stream.Read(_data, 0, 4096);
637 _pos = 0;
638 _sniffed = false;
639 }
640 _mark = -1;
641 _eof = _end == 0;
643 switch (settings.ConformanceLevel)
644 {
645 case ConformanceLevel.Auto:
646 _docState = 0;
647 break;
648 case ConformanceLevel.Fragment:
649 _docState = 9;
650 break;
651 case ConformanceLevel.Document:
652 _docState = 1;
653 break;
654 }
656 _dtdProcessing = settings.DtdProcessing;
661 }
662
663 public override string GetAttribute(string name, string ns)
664 {
665 if (ScanState.XmlText == _state)
666 {
667 return _textXmlReader.GetAttribute(name, ns);
668 }
669 if (name == null)
670 {
671 throw new ArgumentNullException("name");
672 }
673 if (ns == null)
674 {
675 ns = string.Empty;
676 }
677 int num = LocateAttribute(name, ns);
678 if (-1 == num)
679 {
680 return null;
681 }
682 return GetAttribute(num);
683 }
684
685 public override string GetAttribute(string name)
686 {
687 if (ScanState.XmlText == _state)
688 {
689 return _textXmlReader.GetAttribute(name);
690 }
691 int num = LocateAttribute(name);
692 if (-1 == num)
693 {
694 return null;
695 }
696 return GetAttribute(num);
697 }
698
699 public override string GetAttribute(int i)
700 {
701 if (ScanState.XmlText == _state)
702 {
704 }
706 {
707 throw new ArgumentOutOfRangeException("i");
708 }
709 return GetAttributeText(i);
710 }
711
712 public override bool MoveToAttribute(string name, string ns)
713 {
714 if (ScanState.XmlText == _state)
715 {
717 }
718 if (name == null)
719 {
720 throw new ArgumentNullException("name");
721 }
722 if (ns == null)
723 {
724 ns = string.Empty;
725 }
726 int num = LocateAttribute(name, ns);
727 if (-1 != num && _state < ScanState.Init)
728 {
729 PositionOnAttribute(num + 1);
730 return true;
731 }
732 return false;
733 }
734
735 public override bool MoveToAttribute(string name)
736 {
737 if (ScanState.XmlText == _state)
738 {
740 }
741 int num = LocateAttribute(name);
742 if (-1 != num && _state < ScanState.Init)
743 {
744 PositionOnAttribute(num + 1);
745 return true;
746 }
747 return false;
748 }
749
750 public override void MoveToAttribute(int i)
751 {
752 if (ScanState.XmlText == _state)
753 {
756 return;
757 }
759 {
760 throw new ArgumentOutOfRangeException("i");
761 }
762 PositionOnAttribute(i + 1);
763 }
764
765 public override bool MoveToFirstAttribute()
766 {
767 if (ScanState.XmlText == _state)
768 {
770 }
771 if (_attrCount == 0)
772 {
773 return false;
774 }
776 return true;
777 }
778
779 public override bool MoveToNextAttribute()
780 {
781 switch (_state)
782 {
783 case ScanState.Doc:
784 case ScanState.Attr:
785 case ScanState.AttrVal:
786 case ScanState.AttrValPseudoValue:
787 if (_attrIndex >= _attrCount)
788 {
789 return false;
790 }
792 return true;
793 case ScanState.XmlText:
795 default:
796 return false;
797 }
798 }
799
800 public override bool MoveToElement()
801 {
802 switch (_state)
803 {
804 case ScanState.Attr:
805 case ScanState.AttrVal:
806 case ScanState.AttrValPseudoValue:
807 _attrIndex = 0;
809 if (XmlNodeType.Element == _parentNodeType)
810 {
811 _token = BinXmlToken.Element;
812 }
813 else if (XmlNodeType.XmlDeclaration == _parentNodeType)
814 {
815 _token = BinXmlToken.XmlDecl;
816 }
817 else if (XmlNodeType.DocumentType == _parentNodeType)
818 {
819 _token = BinXmlToken.DocType;
820 }
822 _state = ScanState.Doc;
824 _stringValue = null;
825 return true;
826 case ScanState.XmlText:
828 default:
829 return false;
830 }
831 }
832
833 public override bool ReadAttributeValue()
834 {
835 _stringValue = null;
836 switch (_state)
837 {
838 case ScanState.Attr:
839 if (_attributes[_attrIndex - 1].val == null)
840 {
843 if (BinXmlToken.Attr == binXmlToken || BinXmlToken.EndAttrs == binXmlToken)
844 {
845 return false;
846 }
850 _state = ScanState.AttrVal;
851 }
852 else
853 {
854 _token = BinXmlToken.Error;
856 _state = ScanState.AttrValPseudoValue;
857 }
859 _nodetype = XmlNodeType.Text;
860 return true;
861 case ScanState.AttrVal:
862 return false;
863 case ScanState.XmlText:
865 default:
866 return false;
867 }
868 }
869
870 public override void Close()
871 {
872 _state = ScanState.Closed;
873 _nodetype = XmlNodeType.None;
874 _token = BinXmlToken.Error;
875 _stringValue = null;
876 if (_textXmlReader != null)
877 {
879 _textXmlReader = null;
880 }
881 if (_inStrm != null && _closeInput)
882 {
884 }
885 _inStrm = null;
886 _pos = (_end = 0);
887 }
888
889 public override string LookupNamespace(string prefix)
890 {
891 if (ScanState.XmlText == _state)
892 {
894 }
896 {
897 return value.uri;
898 }
899 return null;
900 }
901
902 public override void ResolveEntity()
903 {
904 throw new NotSupportedException();
905 }
906
907 public override bool Read()
908 {
909 try
910 {
911 switch (_state)
912 {
913 case ScanState.Init:
914 return ReadInit(skipXmlDecl: false);
915 case ScanState.Doc:
916 return ReadDoc();
917 case ScanState.XmlText:
918 if (_textXmlReader.Read())
919 {
920 return UpdateFromTextReader(needUpdate: true);
921 }
922 _state = ScanState.Doc;
923 _nodetype = XmlNodeType.None;
924 _isEmpty = false;
925 goto case ScanState.Doc;
926 case ScanState.Attr:
927 case ScanState.AttrVal:
928 case ScanState.AttrValPseudoValue:
930 goto case ScanState.Doc;
931 default:
932 return false;
933 }
934 }
935 catch (OverflowException ex)
936 {
937 _state = ScanState.Error;
938 throw new XmlException(ex.Message, ex);
939 }
940 catch
941 {
942 _state = ScanState.Error;
943 throw;
944 }
945 }
946
947 private bool SetupContentAsXXX(string name)
948 {
950 {
952 }
953 switch (_state)
954 {
955 case ScanState.Doc:
956 if (NodeType == XmlNodeType.EndElement)
957 {
958 return true;
959 }
960 if (NodeType == XmlNodeType.ProcessingInstruction || NodeType == XmlNodeType.Comment)
961 {
962 while (Read() && (NodeType == XmlNodeType.ProcessingInstruction || NodeType == XmlNodeType.Comment))
963 {
964 }
965 if (NodeType == XmlNodeType.EndElement)
966 {
967 return true;
968 }
969 }
970 if (_hasTypedValue)
971 {
972 return true;
973 }
974 break;
975 case ScanState.Attr:
976 {
979 if (BinXmlToken.Attr != binXmlToken && BinXmlToken.EndAttrs != binXmlToken)
980 {
983 return true;
984 }
985 break;
986 }
987 case ScanState.AttrVal:
988 return true;
989 }
990 return false;
991 }
992
994 {
995 if (_state == ScanState.Doc)
996 {
997 if (NodeType != XmlNodeType.Element && NodeType != XmlNodeType.EndElement)
998 {
999 while (Read())
1000 {
1001 XmlNodeType nodeType = NodeType;
1002 if (nodeType == XmlNodeType.Element)
1003 {
1004 break;
1005 }
1006 if ((uint)(nodeType - 7) > 1u)
1007 {
1008 if (nodeType == XmlNodeType.EndElement)
1009 {
1010 break;
1011 }
1013 }
1014 }
1015 }
1016 return _pos;
1017 }
1018 return origPos;
1019 }
1020
1021 public override bool ReadContentAsBoolean()
1022 {
1023 int num = _pos;
1024 bool flag = false;
1025 try
1026 {
1027 if (SetupContentAsXXX("ReadContentAsBoolean"))
1028 {
1029 try
1030 {
1031 switch (_token)
1032 {
1033 case BinXmlToken.XSD_BOOLEAN:
1034 flag = _data[_tokDataPos] != 0;
1035 goto IL_0165;
1036 case BinXmlToken.SQL_SMALLINT:
1037 case BinXmlToken.SQL_INT:
1038 case BinXmlToken.SQL_REAL:
1039 case BinXmlToken.SQL_FLOAT:
1040 case BinXmlToken.SQL_MONEY:
1041 case BinXmlToken.SQL_BIT:
1042 case BinXmlToken.SQL_TINYINT:
1043 case BinXmlToken.SQL_BIGINT:
1044 case BinXmlToken.SQL_UUID:
1045 case BinXmlToken.SQL_DECIMAL:
1046 case BinXmlToken.SQL_NUMERIC:
1047 case BinXmlToken.SQL_BINARY:
1048 case BinXmlToken.SQL_VARBINARY:
1049 case BinXmlToken.SQL_DATETIME:
1050 case BinXmlToken.SQL_SMALLDATETIME:
1051 case BinXmlToken.SQL_SMALLMONEY:
1052 case BinXmlToken.SQL_IMAGE:
1053 case BinXmlToken.SQL_UDT:
1054 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
1055 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
1056 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
1057 case BinXmlToken.XSD_KATMAI_TIME:
1058 case BinXmlToken.XSD_KATMAI_DATETIME:
1059 case BinXmlToken.XSD_KATMAI_DATE:
1060 case BinXmlToken.XSD_TIME:
1061 case BinXmlToken.XSD_DATETIME:
1062 case BinXmlToken.XSD_DATE:
1063 case BinXmlToken.XSD_BINHEX:
1064 case BinXmlToken.XSD_BASE64:
1065 case BinXmlToken.XSD_DECIMAL:
1066 case BinXmlToken.XSD_BYTE:
1067 case BinXmlToken.XSD_UNSIGNEDSHORT:
1068 case BinXmlToken.XSD_UNSIGNEDINT:
1069 case BinXmlToken.XSD_UNSIGNEDLONG:
1070 case BinXmlToken.XSD_QNAME:
1072 case BinXmlToken.EndElem:
1073 case BinXmlToken.Element:
1074 return XmlConvert.ToBoolean(string.Empty);
1075 }
1076 }
1078 {
1080 }
1082 {
1084 }
1085 }
1086 goto end_IL_0009;
1087 IL_0165:
1088 num = FinishContentAsXXX(num);
1089 return flag;
1090 end_IL_0009:;
1091 }
1092 finally
1093 {
1094 _pos = num;
1095 }
1096 return base.ReadContentAsBoolean();
1097 }
1098
1100 {
1101 int num = _pos;
1102 try
1103 {
1104 DateTime result;
1105 if (SetupContentAsXXX("ReadContentAsDateTime"))
1106 {
1107 try
1108 {
1109 switch (_token)
1110 {
1111 case BinXmlToken.SQL_DATETIME:
1112 case BinXmlToken.SQL_SMALLDATETIME:
1113 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
1114 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
1115 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
1116 case BinXmlToken.XSD_KATMAI_TIME:
1117 case BinXmlToken.XSD_KATMAI_DATETIME:
1118 case BinXmlToken.XSD_KATMAI_DATE:
1119 case BinXmlToken.XSD_TIME:
1120 case BinXmlToken.XSD_DATETIME:
1121 case BinXmlToken.XSD_DATE:
1122 result = ValueAsDateTime();
1123 goto IL_016f;
1124 case BinXmlToken.SQL_SMALLINT:
1125 case BinXmlToken.SQL_INT:
1126 case BinXmlToken.SQL_REAL:
1127 case BinXmlToken.SQL_FLOAT:
1128 case BinXmlToken.SQL_MONEY:
1129 case BinXmlToken.SQL_BIT:
1130 case BinXmlToken.SQL_TINYINT:
1131 case BinXmlToken.SQL_BIGINT:
1132 case BinXmlToken.SQL_UUID:
1133 case BinXmlToken.SQL_DECIMAL:
1134 case BinXmlToken.SQL_NUMERIC:
1135 case BinXmlToken.SQL_BINARY:
1136 case BinXmlToken.SQL_VARBINARY:
1137 case BinXmlToken.SQL_SMALLMONEY:
1138 case BinXmlToken.SQL_IMAGE:
1139 case BinXmlToken.SQL_UDT:
1140 case BinXmlToken.XSD_BINHEX:
1141 case BinXmlToken.XSD_BASE64:
1142 case BinXmlToken.XSD_BOOLEAN:
1143 case BinXmlToken.XSD_DECIMAL:
1144 case BinXmlToken.XSD_BYTE:
1145 case BinXmlToken.XSD_UNSIGNEDSHORT:
1146 case BinXmlToken.XSD_UNSIGNEDINT:
1147 case BinXmlToken.XSD_UNSIGNEDLONG:
1148 case BinXmlToken.XSD_QNAME:
1150 case BinXmlToken.EndElem:
1151 case BinXmlToken.Element:
1152 return XmlConvert.ToDateTime(string.Empty, XmlDateTimeSerializationMode.RoundtripKind);
1153 }
1154 }
1156 {
1158 }
1160 {
1162 }
1164 {
1166 }
1167 }
1168 goto end_IL_0007;
1169 IL_016f:
1170 num = FinishContentAsXXX(num);
1171 return result;
1172 end_IL_0007:;
1173 }
1174 finally
1175 {
1176 _pos = num;
1177 }
1178 return base.ReadContentAsDateTime();
1179 }
1180
1181 public override double ReadContentAsDouble()
1182 {
1183 int num = _pos;
1184 try
1185 {
1186 double result;
1187 if (SetupContentAsXXX("ReadContentAsDouble"))
1188 {
1189 try
1190 {
1191 switch (_token)
1192 {
1193 case BinXmlToken.SQL_REAL:
1194 case BinXmlToken.SQL_FLOAT:
1195 result = ValueAsDouble();
1196 goto IL_0132;
1197 case BinXmlToken.SQL_SMALLINT:
1198 case BinXmlToken.SQL_INT:
1199 case BinXmlToken.SQL_MONEY:
1200 case BinXmlToken.SQL_BIT:
1201 case BinXmlToken.SQL_TINYINT:
1202 case BinXmlToken.SQL_BIGINT:
1203 case BinXmlToken.SQL_UUID:
1204 case BinXmlToken.SQL_DECIMAL:
1205 case BinXmlToken.SQL_NUMERIC:
1206 case BinXmlToken.SQL_BINARY:
1207 case BinXmlToken.SQL_VARBINARY:
1208 case BinXmlToken.SQL_DATETIME:
1209 case BinXmlToken.SQL_SMALLDATETIME:
1210 case BinXmlToken.SQL_SMALLMONEY:
1211 case BinXmlToken.SQL_IMAGE:
1212 case BinXmlToken.SQL_UDT:
1213 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
1214 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
1215 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
1216 case BinXmlToken.XSD_KATMAI_TIME:
1217 case BinXmlToken.XSD_KATMAI_DATETIME:
1218 case BinXmlToken.XSD_KATMAI_DATE:
1219 case BinXmlToken.XSD_TIME:
1220 case BinXmlToken.XSD_DATETIME:
1221 case BinXmlToken.XSD_DATE:
1222 case BinXmlToken.XSD_BINHEX:
1223 case BinXmlToken.XSD_BASE64:
1224 case BinXmlToken.XSD_BOOLEAN:
1225 case BinXmlToken.XSD_DECIMAL:
1226 case BinXmlToken.XSD_BYTE:
1227 case BinXmlToken.XSD_UNSIGNEDSHORT:
1228 case BinXmlToken.XSD_UNSIGNEDINT:
1229 case BinXmlToken.XSD_UNSIGNEDLONG:
1230 case BinXmlToken.XSD_QNAME:
1232 case BinXmlToken.EndElem:
1233 case BinXmlToken.Element:
1234 return XmlConvert.ToDouble(string.Empty);
1235 }
1236 }
1238 {
1240 }
1242 {
1244 }
1246 {
1248 }
1249 }
1250 goto end_IL_0007;
1251 IL_0132:
1252 num = FinishContentAsXXX(num);
1253 return result;
1254 end_IL_0007:;
1255 }
1256 finally
1257 {
1258 _pos = num;
1259 }
1260 return base.ReadContentAsDouble();
1261 }
1262
1263 public override float ReadContentAsFloat()
1264 {
1265 int num = _pos;
1266 try
1267 {
1268 float result;
1269 if (SetupContentAsXXX("ReadContentAsFloat"))
1270 {
1271 try
1272 {
1273 switch (_token)
1274 {
1275 case BinXmlToken.SQL_REAL:
1276 case BinXmlToken.SQL_FLOAT:
1277 result = (float)ValueAsDouble();
1278 goto IL_0133;
1279 case BinXmlToken.SQL_SMALLINT:
1280 case BinXmlToken.SQL_INT:
1281 case BinXmlToken.SQL_MONEY:
1282 case BinXmlToken.SQL_BIT:
1283 case BinXmlToken.SQL_TINYINT:
1284 case BinXmlToken.SQL_BIGINT:
1285 case BinXmlToken.SQL_UUID:
1286 case BinXmlToken.SQL_DECIMAL:
1287 case BinXmlToken.SQL_NUMERIC:
1288 case BinXmlToken.SQL_BINARY:
1289 case BinXmlToken.SQL_VARBINARY:
1290 case BinXmlToken.SQL_DATETIME:
1291 case BinXmlToken.SQL_SMALLDATETIME:
1292 case BinXmlToken.SQL_SMALLMONEY:
1293 case BinXmlToken.SQL_IMAGE:
1294 case BinXmlToken.SQL_UDT:
1295 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
1296 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
1297 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
1298 case BinXmlToken.XSD_KATMAI_TIME:
1299 case BinXmlToken.XSD_KATMAI_DATETIME:
1300 case BinXmlToken.XSD_KATMAI_DATE:
1301 case BinXmlToken.XSD_TIME:
1302 case BinXmlToken.XSD_DATETIME:
1303 case BinXmlToken.XSD_DATE:
1304 case BinXmlToken.XSD_BINHEX:
1305 case BinXmlToken.XSD_BASE64:
1306 case BinXmlToken.XSD_BOOLEAN:
1307 case BinXmlToken.XSD_DECIMAL:
1308 case BinXmlToken.XSD_BYTE:
1309 case BinXmlToken.XSD_UNSIGNEDSHORT:
1310 case BinXmlToken.XSD_UNSIGNEDINT:
1311 case BinXmlToken.XSD_UNSIGNEDLONG:
1312 case BinXmlToken.XSD_QNAME:
1314 case BinXmlToken.EndElem:
1315 case BinXmlToken.Element:
1316 return XmlConvert.ToSingle(string.Empty);
1317 }
1318 }
1320 {
1322 }
1324 {
1326 }
1328 {
1330 }
1331 }
1332 goto end_IL_0007;
1333 IL_0133:
1334 num = FinishContentAsXXX(num);
1335 return result;
1336 end_IL_0007:;
1337 }
1338 finally
1339 {
1340 _pos = num;
1341 }
1342 return base.ReadContentAsFloat();
1343 }
1344
1345 public override decimal ReadContentAsDecimal()
1346 {
1347 int num = _pos;
1348 try
1349 {
1350 decimal result;
1351 if (SetupContentAsXXX("ReadContentAsDecimal"))
1352 {
1353 try
1354 {
1355 switch (_token)
1356 {
1357 case BinXmlToken.SQL_SMALLINT:
1358 case BinXmlToken.SQL_INT:
1359 case BinXmlToken.SQL_MONEY:
1360 case BinXmlToken.SQL_BIT:
1361 case BinXmlToken.SQL_TINYINT:
1362 case BinXmlToken.SQL_BIGINT:
1363 case BinXmlToken.SQL_DECIMAL:
1364 case BinXmlToken.SQL_NUMERIC:
1365 case BinXmlToken.SQL_SMALLMONEY:
1366 case BinXmlToken.XSD_DECIMAL:
1367 case BinXmlToken.XSD_BYTE:
1368 case BinXmlToken.XSD_UNSIGNEDSHORT:
1369 case BinXmlToken.XSD_UNSIGNEDINT:
1370 case BinXmlToken.XSD_UNSIGNEDLONG:
1371 result = ValueAsDecimal();
1372 goto IL_016e;
1373 case BinXmlToken.SQL_REAL:
1374 case BinXmlToken.SQL_FLOAT:
1375 case BinXmlToken.SQL_UUID:
1376 case BinXmlToken.SQL_BINARY:
1377 case BinXmlToken.SQL_VARBINARY:
1378 case BinXmlToken.SQL_DATETIME:
1379 case BinXmlToken.SQL_SMALLDATETIME:
1380 case BinXmlToken.SQL_IMAGE:
1381 case BinXmlToken.SQL_UDT:
1382 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
1383 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
1384 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
1385 case BinXmlToken.XSD_KATMAI_TIME:
1386 case BinXmlToken.XSD_KATMAI_DATETIME:
1387 case BinXmlToken.XSD_KATMAI_DATE:
1388 case BinXmlToken.XSD_TIME:
1389 case BinXmlToken.XSD_DATETIME:
1390 case BinXmlToken.XSD_DATE:
1391 case BinXmlToken.XSD_BINHEX:
1392 case BinXmlToken.XSD_BASE64:
1393 case BinXmlToken.XSD_BOOLEAN:
1394 case BinXmlToken.XSD_QNAME:
1396 case BinXmlToken.EndElem:
1397 case BinXmlToken.Element:
1398 return XmlConvert.ToDecimal(string.Empty);
1399 }
1400 }
1402 {
1404 }
1406 {
1408 }
1410 {
1412 }
1413 }
1414 goto end_IL_0007;
1415 IL_016e:
1416 num = FinishContentAsXXX(num);
1417 return result;
1418 end_IL_0007:;
1419 }
1420 finally
1421 {
1422 _pos = num;
1423 }
1424 return base.ReadContentAsDecimal();
1425 }
1426
1427 public override int ReadContentAsInt()
1428 {
1429 int num = _pos;
1430 try
1431 {
1432 int result;
1433 if (SetupContentAsXXX("ReadContentAsInt"))
1434 {
1435 try
1436 {
1437 switch (_token)
1438 {
1439 case BinXmlToken.SQL_SMALLINT:
1440 case BinXmlToken.SQL_INT:
1441 case BinXmlToken.SQL_MONEY:
1442 case BinXmlToken.SQL_BIT:
1443 case BinXmlToken.SQL_TINYINT:
1444 case BinXmlToken.SQL_BIGINT:
1445 case BinXmlToken.SQL_DECIMAL:
1446 case BinXmlToken.SQL_NUMERIC:
1447 case BinXmlToken.SQL_SMALLMONEY:
1448 case BinXmlToken.XSD_DECIMAL:
1449 case BinXmlToken.XSD_BYTE:
1450 case BinXmlToken.XSD_UNSIGNEDSHORT:
1451 case BinXmlToken.XSD_UNSIGNEDINT:
1452 case BinXmlToken.XSD_UNSIGNEDLONG:
1453 result = checked((int)ValueAsLong());
1454 goto IL_016f;
1455 case BinXmlToken.SQL_REAL:
1456 case BinXmlToken.SQL_FLOAT:
1457 case BinXmlToken.SQL_UUID:
1458 case BinXmlToken.SQL_BINARY:
1459 case BinXmlToken.SQL_VARBINARY:
1460 case BinXmlToken.SQL_DATETIME:
1461 case BinXmlToken.SQL_SMALLDATETIME:
1462 case BinXmlToken.SQL_IMAGE:
1463 case BinXmlToken.SQL_UDT:
1464 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
1465 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
1466 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
1467 case BinXmlToken.XSD_KATMAI_TIME:
1468 case BinXmlToken.XSD_KATMAI_DATETIME:
1469 case BinXmlToken.XSD_KATMAI_DATE:
1470 case BinXmlToken.XSD_TIME:
1471 case BinXmlToken.XSD_DATETIME:
1472 case BinXmlToken.XSD_DATE:
1473 case BinXmlToken.XSD_BINHEX:
1474 case BinXmlToken.XSD_BASE64:
1475 case BinXmlToken.XSD_BOOLEAN:
1476 case BinXmlToken.XSD_QNAME:
1478 case BinXmlToken.EndElem:
1479 case BinXmlToken.Element:
1480 return XmlConvert.ToInt32(string.Empty);
1481 }
1482 }
1484 {
1486 }
1488 {
1490 }
1492 {
1494 }
1495 }
1496 goto end_IL_0007;
1497 IL_016f:
1498 num = FinishContentAsXXX(num);
1499 return result;
1500 end_IL_0007:;
1501 }
1502 finally
1503 {
1504 _pos = num;
1505 }
1506 return base.ReadContentAsInt();
1507 }
1508
1509 public override long ReadContentAsLong()
1510 {
1511 int num = _pos;
1512 try
1513 {
1514 long result;
1515 if (SetupContentAsXXX("ReadContentAsLong"))
1516 {
1517 try
1518 {
1519 switch (_token)
1520 {
1521 case BinXmlToken.SQL_SMALLINT:
1522 case BinXmlToken.SQL_INT:
1523 case BinXmlToken.SQL_MONEY:
1524 case BinXmlToken.SQL_BIT:
1525 case BinXmlToken.SQL_TINYINT:
1526 case BinXmlToken.SQL_BIGINT:
1527 case BinXmlToken.SQL_DECIMAL:
1528 case BinXmlToken.SQL_NUMERIC:
1529 case BinXmlToken.SQL_SMALLMONEY:
1530 case BinXmlToken.XSD_DECIMAL:
1531 case BinXmlToken.XSD_BYTE:
1532 case BinXmlToken.XSD_UNSIGNEDSHORT:
1533 case BinXmlToken.XSD_UNSIGNEDINT:
1534 case BinXmlToken.XSD_UNSIGNEDLONG:
1535 result = ValueAsLong();
1536 goto IL_016e;
1537 case BinXmlToken.SQL_REAL:
1538 case BinXmlToken.SQL_FLOAT:
1539 case BinXmlToken.SQL_UUID:
1540 case BinXmlToken.SQL_BINARY:
1541 case BinXmlToken.SQL_VARBINARY:
1542 case BinXmlToken.SQL_DATETIME:
1543 case BinXmlToken.SQL_SMALLDATETIME:
1544 case BinXmlToken.SQL_IMAGE:
1545 case BinXmlToken.SQL_UDT:
1546 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
1547 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
1548 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
1549 case BinXmlToken.XSD_KATMAI_TIME:
1550 case BinXmlToken.XSD_KATMAI_DATETIME:
1551 case BinXmlToken.XSD_KATMAI_DATE:
1552 case BinXmlToken.XSD_TIME:
1553 case BinXmlToken.XSD_DATETIME:
1554 case BinXmlToken.XSD_DATE:
1555 case BinXmlToken.XSD_BINHEX:
1556 case BinXmlToken.XSD_BASE64:
1557 case BinXmlToken.XSD_BOOLEAN:
1558 case BinXmlToken.XSD_QNAME:
1560 case BinXmlToken.EndElem:
1561 case BinXmlToken.Element:
1562 return XmlConvert.ToInt64(string.Empty);
1563 }
1564 }
1566 {
1568 }
1570 {
1572 }
1574 {
1576 }
1577 }
1578 goto end_IL_0007;
1579 IL_016e:
1580 num = FinishContentAsXXX(num);
1581 return result;
1582 end_IL_0007:;
1583 }
1584 finally
1585 {
1586 _pos = num;
1587 }
1588 return base.ReadContentAsLong();
1589 }
1590
1591 public override object ReadContentAsObject()
1592 {
1593 int num = _pos;
1594 try
1595 {
1596 if (SetupContentAsXXX("ReadContentAsObject"))
1597 {
1598 object result;
1599 try
1600 {
1601 result = ((NodeType != XmlNodeType.Element && NodeType != XmlNodeType.EndElement) ? ValueAsObject(_token, returnInternalTypes: false) : string.Empty);
1602 }
1604 {
1606 }
1608 {
1610 }
1612 {
1614 }
1615 num = FinishContentAsXXX(num);
1616 return result;
1617 }
1618 }
1619 finally
1620 {
1621 _pos = num;
1622 }
1623 return base.ReadContentAsObject();
1624 }
1625
1627 {
1628 int num = _pos;
1629 try
1630 {
1631 if (SetupContentAsXXX("ReadContentAs"))
1632 {
1633 object result;
1634 try
1635 {
1636 result = ((NodeType != XmlNodeType.Element && NodeType != XmlNodeType.EndElement) ? ((!(returnType == ValueType) && !(returnType == typeof(object))) ? ValueAs(_token, returnType, namespaceResolver) : ValueAsObject(_token, returnInternalTypes: false)) : string.Empty);
1637 }
1639 {
1641 }
1643 {
1645 }
1647 {
1649 }
1650 num = FinishContentAsXXX(num);
1651 return result;
1652 }
1653 }
1654 finally
1655 {
1656 _pos = num;
1657 }
1658 return base.ReadContentAs(returnType, namespaceResolver);
1659 }
1660
1662 {
1663 if (ScanState.XmlText == _state)
1664 {
1666 return xmlNamespaceResolver.GetNamespacesInScope(scope);
1667 }
1669 if (XmlNamespaceScope.Local == scope)
1670 {
1671 if (_elemDepth > 0)
1672 {
1674 {
1675 dictionary.Add(namespaceDecl.prefix, namespaceDecl.uri);
1676 }
1677 }
1678 }
1679 else
1680 {
1682 {
1683 if ((value.scope != -1 || (scope == XmlNamespaceScope.All && "xml" == value.prefix)) && (value.prefix.Length > 0 || value.uri.Length > 0))
1684 {
1685 dictionary.Add(value.prefix, value.uri);
1686 }
1687 }
1688 }
1689 return dictionary;
1690 }
1691
1693 {
1694 if (ScanState.XmlText == _state)
1695 {
1697 return xmlNamespaceResolver.LookupPrefix(namespaceName);
1698 }
1699 if (namespaceName == null)
1700 {
1701 return null;
1702 }
1703 string text = _xnt.Get(namespaceName);
1704 if (text == null)
1705 {
1706 return null;
1707 }
1708 for (int num = _elemDepth; num >= 0; num--)
1709 {
1710 for (NamespaceDecl namespaceDecl = _elementStack[num].nsdecls; namespaceDecl != null; namespaceDecl = namespaceDecl.scopeLink)
1711 {
1712 if ((object)namespaceDecl.uri == text)
1713 {
1714 return namespaceDecl.prefix;
1715 }
1716 }
1717 }
1718 return null;
1719 }
1720
1722 {
1724 {
1725 throw ThrowUnexpectedToken(token);
1726 }
1727 }
1728
1729 private void AddInitNamespace(string prefix, string uri)
1730 {
1731 NamespaceDecl namespaceDecl = new NamespaceDecl(prefix, uri, _elementStack[0].nsdecls, null, -1, implied: true);
1734 }
1735
1736 private void AddName()
1737 {
1738 string array = ParseText();
1739 int num = _symbolTables.symCount++;
1740 string[] array2 = _symbolTables.symtable;
1741 if (num == array2.Length)
1742 {
1743 string[] array3 = new string[checked(num * 2)];
1744 Array.Copy(array2, array3, num);
1746 }
1747 array2[num] = _xnt.Add(array);
1748 }
1749
1750 private void AddQName()
1751 {
1752 int num = ReadNameRef();
1753 int num2 = ReadNameRef();
1754 int num3 = ReadNameRef();
1757 if (num4 == array.Length)
1758 {
1759 QName[] array2 = new QName[checked(num4 * 2)];
1762 }
1763 string[] symtable = _symbolTables.symtable;
1764 string text = symtable[num2];
1765 string lname;
1766 string nsUri;
1767 if (num3 == 0)
1768 {
1769 if (num2 == 0 && num == 0)
1770 {
1771 return;
1772 }
1773 if (!text.StartsWith("xmlns", StringComparison.Ordinal))
1774 {
1775 goto IL_0104;
1776 }
1777 if (5 < text.Length)
1778 {
1779 if (6 == text.Length || ':' != text[5])
1780 {
1781 goto IL_0104;
1782 }
1783 lname = _xnt.Add(text.Substring(6));
1784 text = _xmlns;
1785 }
1786 else
1787 {
1788 lname = text;
1789 text = string.Empty;
1790 }
1791 nsUri = _nsxmlns;
1792 }
1793 else
1794 {
1795 lname = symtable[num3];
1796 nsUri = symtable[num];
1797 }
1798 array[num4].Set(text, lname, nsUri);
1799 return;
1800 IL_0104:
1801 throw new XmlException(System.SR.Xml_BadNamespaceDecl, (string[])null);
1802 }
1803
1810
1811 private void SkipExtn()
1812 {
1813 int num = ParseMB32();
1814 checked
1815 {
1816 _pos += num;
1817 Fill(-1);
1818 }
1819 }
1820
1821 private int ReadQNameRef()
1822 {
1823 int num = ParseMB32();
1825 {
1826 throw new XmlException(System.SR.XmlBin_InvalidQNameID, string.Empty);
1827 }
1828 return num;
1829 }
1830
1831 private int ReadNameRef()
1832 {
1833 int num = ParseMB32();
1835 {
1836 throw new XmlException(System.SR.XmlBin_InvalidQNameID, string.Empty);
1837 }
1838 return num;
1839 }
1840
1841 private bool FillAllowEOF()
1842 {
1843 if (_eof)
1844 {
1845 return false;
1846 }
1847 byte[] array = _data;
1848 int pos = _pos;
1849 int num = _mark;
1850 int end = _end;
1851 if (num == -1)
1852 {
1853 num = pos;
1854 }
1855 if (num >= 0 && num < end)
1856 {
1857 int num2 = end - num;
1858 if (num2 > 7 * (array.Length / 8))
1859 {
1860 byte[] array2 = new byte[checked(array.Length * 2)];
1861 Array.Copy(array, num, array2, 0, num2);
1862 array = (_data = array2);
1863 }
1864 else
1865 {
1866 Array.Copy(array, num, array, 0, num2);
1867 }
1868 pos -= num;
1869 end -= num;
1870 _tokDataPos -= num;
1871 for (int i = 0; i < _attrCount; i++)
1872 {
1873 _attributes[i].AdjustPosition(-num);
1874 }
1875 _pos = pos;
1876 _mark = 0;
1877 }
1878 else
1879 {
1880 _pos -= end;
1881 _mark -= end;
1882 _tokDataPos -= end;
1883 end = 0;
1884 }
1885 int count = array.Length - end;
1886 int num3 = _inStrm.Read(array, end, count);
1887 _end = end + num3;
1888 _eof = num3 <= 0;
1889 return num3 > 0;
1890 }
1891
1892 private void Fill_(int require)
1893 {
1894 while (FillAllowEOF() && _pos + require >= _end)
1895 {
1896 }
1897 if (_pos + require >= _end)
1898 {
1900 }
1901 }
1902
1903 private void Fill(int require)
1904 {
1905 if (_pos + require >= _end)
1906 {
1907 Fill_(require);
1908 }
1909 }
1910
1911 private byte ReadByte()
1912 {
1913 Fill(0);
1914 return _data[_pos++];
1915 }
1916
1917 private ushort ReadUShort()
1918 {
1919 Fill(1);
1920 int pos = _pos;
1921 byte[] data = _data;
1922 ushort result = (ushort)(data[pos] + (data[pos + 1] << 8));
1923 _pos += 2;
1924 return result;
1925 }
1926
1927 private int ParseMB32()
1928 {
1929 byte b = ReadByte();
1930 if (b > 127)
1931 {
1932 return ParseMB32_(b);
1933 }
1934 return b;
1935 }
1936
1937 private int ParseMB32_(byte b)
1938 {
1939 uint num = b & 0x7Fu;
1940 b = ReadByte();
1941 uint num2 = b & 0x7Fu;
1942 num += num2 << 7;
1943 if (b > 127)
1944 {
1945 b = ReadByte();
1946 num2 = b & 0x7Fu;
1947 num += num2 << 14;
1948 if (b > 127)
1949 {
1950 b = ReadByte();
1951 num2 = b & 0x7Fu;
1952 num += num2 << 21;
1953 if (b > 127)
1954 {
1955 b = ReadByte();
1956 num2 = b & 7u;
1957 if (b > 7)
1958 {
1960 }
1961 num += num2 << 28;
1962 }
1963 }
1964 }
1965 return (int)num;
1966 }
1967
1968 private int ParseMB32(int pos)
1969 {
1970 byte[] data = _data;
1971 byte b = data[pos++];
1972 uint num = b & 0x7Fu;
1973 if (b > 127)
1974 {
1975 b = data[pos++];
1976 uint num2 = b & 0x7Fu;
1977 num += num2 << 7;
1978 if (b > 127)
1979 {
1980 b = data[pos++];
1981 num2 = b & 0x7Fu;
1982 num += num2 << 14;
1983 if (b > 127)
1984 {
1985 b = data[pos++];
1986 num2 = b & 0x7Fu;
1987 num += num2 << 21;
1988 if (b > 127)
1989 {
1990 b = data[pos++];
1991 num2 = b & 7u;
1992 if (b > 7)
1993 {
1995 }
1996 num += num2 << 28;
1997 }
1998 }
1999 }
2000 }
2001 return (int)num;
2002 }
2003
2004 private int ParseMB64()
2005 {
2006 byte b = ReadByte();
2007 if (b > 127)
2008 {
2009 return ParseMB32_(b);
2010 }
2011 return b;
2012 }
2013
2015 {
2016 while (_pos >= _end && FillAllowEOF())
2017 {
2018 }
2019 if (_pos >= _end)
2020 {
2021 return BinXmlToken.EOF;
2022 }
2023 return (BinXmlToken)_data[_pos];
2024 }
2025
2027 {
2028 while (_pos >= _end && FillAllowEOF())
2029 {
2030 }
2031 if (_pos >= _end)
2032 {
2033 return BinXmlToken.EOF;
2034 }
2035 return (BinXmlToken)_data[_pos++];
2036 }
2037
2039 {
2040 while (true)
2041 {
2042 switch (token)
2043 {
2044 case BinXmlToken.Name:
2045 AddName();
2046 break;
2047 case BinXmlToken.QName:
2048 AddQName();
2049 break;
2050 case BinXmlToken.NmFlush:
2051 NameFlush();
2052 break;
2053 case BinXmlToken.Extn:
2054 SkipExtn();
2055 break;
2056 default:
2057 return token;
2058 }
2059 token = ReadToken();
2060 }
2061 }
2062
2064 {
2065 int pos = _pos;
2067 if (pos >= _end)
2068 {
2070 }
2071 else
2072 {
2074 _pos = pos + 1;
2075 }
2076 if (binXmlToken >= BinXmlToken.NmFlush && binXmlToken <= BinXmlToken.Name)
2077 {
2078 return NextToken2(binXmlToken);
2079 }
2080 return binXmlToken;
2081 }
2082
2084 {
2085 int pos = _pos;
2086 if (pos < _end)
2087 {
2090 {
2091 _pos = pos + 1;
2092 return binXmlToken;
2093 }
2094 }
2095 return NextToken1();
2096 }
2097
2099 {
2101 if (BinXmlToken.EOF != binXmlToken)
2102 {
2103 _pos--;
2104 }
2105 return binXmlToken;
2106 }
2107
2109 {
2110 checked
2111 {
2112 while (true)
2113 {
2115 switch (binXmlToken)
2116 {
2117 case BinXmlToken.NmFlush:
2118 break;
2119 case BinXmlToken.Name:
2120 {
2121 int num2 = ParseMB32();
2122 _pos += 2 * num2;
2123 break;
2124 }
2125 case BinXmlToken.QName:
2126 ParseMB32();
2127 ParseMB32();
2128 ParseMB32();
2129 break;
2130 case BinXmlToken.Extn:
2131 {
2132 int num = ParseMB32();
2133 _pos += num;
2134 break;
2135 }
2136 default:
2137 return binXmlToken;
2138 }
2139 }
2140 }
2141 }
2142
2143 private string ParseText()
2144 {
2145 int mark = _mark;
2146 try
2147 {
2148 if (mark < 0)
2149 {
2150 _mark = _pos;
2151 }
2152 int start;
2153 int cch = ScanText(out start);
2154 return GetString(start, cch);
2155 }
2156 finally
2157 {
2158 if (mark < 0)
2159 {
2160 _mark = -1;
2161 }
2162 }
2163 }
2164
2165 private int ScanText(out int start)
2166 {
2167 int num = ParseMB32();
2168 int mark = _mark;
2169 int pos = _pos;
2170 checked
2171 {
2172 _pos += num * 2;
2173 if (_pos > _end)
2174 {
2175 Fill(-1);
2176 }
2177 }
2178 start = pos - (mark - _mark);
2179 return num;
2180 }
2181
2182 private string GetString(int pos, int cch)
2183 {
2184 checked
2185 {
2186 if (pos + cch * 2 > _end)
2187 {
2188 throw new XmlException(System.SR.Xml_UnexpectedEOF1, (string[])null);
2189 }
2190 if (cch == 0)
2191 {
2192 return string.Empty;
2193 }
2194 return string.Create(cch, (_data, pos), delegate(Span<char> dstChars, (byte[] _data, int pos) state)
2195 {
2196 int length = dstChars.Length;
2197 ReadOnlySpan<byte> readOnlySpan = state._data.AsSpan(state.pos, length * 2);
2200 });
2201 }
2202 }
2203
2204 private string GetAttributeText(int i)
2205 {
2206 string val = _attributes[i].val;
2207 if (val != null)
2208 {
2209 return val;
2210 }
2211 int pos = _pos;
2212 try
2213 {
2216 if (BinXmlToken.Attr == binXmlToken || BinXmlToken.EndAttrs == binXmlToken)
2217 {
2218 return "";
2219 }
2222 return ValueAsString(binXmlToken);
2223 }
2224 finally
2225 {
2226 _pos = pos;
2227 }
2228 }
2229
2230 private int LocateAttribute(string name, string ns)
2231 {
2232 for (int i = 0; i < _attrCount; i++)
2233 {
2234 if (_attributes[i].name.MatchNs(name, ns))
2235 {
2236 return i;
2237 }
2238 }
2239 return -1;
2240 }
2241
2242 private int LocateAttribute(string name)
2243 {
2245 for (int i = 0; i < _attrCount; i++)
2246 {
2247 if (_attributes[i].name.MatchPrefix(prefix, lname))
2248 {
2249 return i;
2250 }
2251 }
2252 return -1;
2253 }
2254
2255 private void PositionOnAttribute(int i)
2256 {
2257 _attrIndex = i;
2258 _qnameOther = _attributes[i - 1].name;
2259 if (_state == ScanState.Doc)
2260 {
2262 }
2263 _token = BinXmlToken.Attr;
2264 _nodetype = XmlNodeType.Attribute;
2265 _state = ScanState.Attr;
2267 _stringValue = null;
2268 }
2269
2270 private void GrowElements()
2271 {
2272 int num = _elementStack.Length * 2;
2273 ElemInfo[] array = new ElemInfo[num];
2276 }
2277
2278 private void GrowAttributes()
2279 {
2280 int num = _attributes.Length * 2;
2281 AttrInfo[] array = new AttrInfo[num];
2284 }
2285
2286 private void ClearAttributes()
2287 {
2288 if (_attrCount != 0)
2289 {
2290 _attrCount = 0;
2291 }
2292 }
2293
2294 private void PushNamespace(string prefix, string ns, bool implied)
2295 {
2296 if (prefix == "xml")
2297 {
2298 return;
2299 }
2300 int elemDepth = _elemDepth;
2302 if (value != null)
2303 {
2304 if (value.uri == ns)
2305 {
2306 if (!implied && value.implied && value.scope == elemDepth)
2307 {
2308 value.implied = false;
2309 }
2310 return;
2311 }
2313 if (prefix.Length != 0)
2314 {
2315 for (int i = 0; i < _attrCount; i++)
2316 {
2317 if (_attributes[i].name.prefix.Length != 0)
2318 {
2320 }
2321 }
2322 }
2323 }
2327 }
2328
2330 {
2332 while (namespaceDecl != null)
2333 {
2334 if (namespaceDecl.prevLink == null)
2335 {
2337 }
2338 else
2339 {
2340 _namespaces[namespaceDecl.prefix] = namespaceDecl.prevLink;
2341 }
2342 NamespaceDecl scopeLink = namespaceDecl.scopeLink;
2345 namespaceDecl = scopeLink;
2346 }
2347 }
2348
2350 {
2352 {
2353 if (namespaceDecl.implied)
2354 {
2355 if (_attrCount == _attributes.Length)
2356 {
2358 }
2361 _attrCount++;
2362 }
2363 }
2364 }
2365
2366 private bool ReadInit(bool skipXmlDecl)
2367 {
2368 string text = null;
2369 if (!_sniffed)
2370 {
2371 ushort num = ReadUShort();
2372 if (num != 65503)
2373 {
2375 goto IL_01e6;
2376 }
2377 }
2378 _version = ReadByte();
2379 if (_version != 1 && _version != 2)
2380 {
2382 }
2383 else
2384 {
2385 if (1200 == ReadUShort())
2386 {
2387 _state = ScanState.Doc;
2388 if (BinXmlToken.XmlDecl == PeekToken())
2389 {
2390 _pos++;
2391 _attributes[0].Set(new QName(string.Empty, _xnt.Add("version"), string.Empty), ParseText());
2392 _attrCount = 1;
2393 if (BinXmlToken.Encoding == PeekToken())
2394 {
2395 _pos++;
2396 _attributes[1].Set(new QName(string.Empty, _xnt.Add("encoding"), string.Empty), ParseText());
2397 _attrCount++;
2398 }
2399 byte b = ReadByte();
2400 if (b != 0)
2401 {
2402 if ((uint)(b - 1) > 1u)
2403 {
2405 goto IL_01e6;
2406 }
2407 _attributes[_attrCount].Set(new QName(string.Empty, _xnt.Add("standalone"), string.Empty), (b == 1) ? "yes" : "no");
2408 _attrCount++;
2409 }
2410 if (!skipXmlDecl)
2411 {
2412 QName qnameElement = new QName(string.Empty, _xnt.Add("xml"), string.Empty);
2414 _nodetype = XmlNodeType.XmlDeclaration;
2416 return true;
2417 }
2418 }
2419 return ReadDoc();
2420 }
2422 }
2423 goto IL_01e6;
2424 IL_01e6:
2425 _state = ScanState.Error;
2426 throw new XmlException(text, (string[])null);
2427 }
2428
2429 private void ScanAttributes()
2430 {
2431 int num = -1;
2432 int num2 = -1;
2433 _mark = _pos;
2434 string text = null;
2435 bool flag = false;
2437 while (BinXmlToken.EndAttrs != (binXmlToken = NextToken()))
2438 {
2439 if (BinXmlToken.Attr == binXmlToken)
2440 {
2441 if (text != null)
2442 {
2443 PushNamespace(text, string.Empty, implied: false);
2444 text = null;
2445 }
2446 if (_attrCount == _attributes.Length)
2447 {
2449 }
2452 if (n.prefix == "xml")
2453 {
2454 if (n.localname == "lang")
2455 {
2456 num2 = _attrCount;
2457 }
2458 else if (n.localname == "space")
2459 {
2460 num = _attrCount;
2461 }
2462 }
2463 else if (Ref.Equal(n.namespaceUri, _nsxmlns))
2464 {
2465 text = n.localname;
2466 if (text == "xmlns")
2467 {
2468 text = string.Empty;
2469 }
2470 }
2471 else if (n.prefix.Length != 0)
2472 {
2473 if (n.namespaceUri.Length == 0)
2474 {
2475 throw new XmlException(System.SR.Xml_PrefixForEmptyNs, string.Empty);
2476 }
2477 PushNamespace(n.prefix, n.namespaceUri, implied: true);
2478 }
2479 else if (n.namespaceUri.Length != 0)
2480 {
2481 throw ThrowXmlException(System.SR.XmlBinary_AttrWithNsNoPrefix, n.localname, n.namespaceUri);
2482 }
2483 _attrCount++;
2484 flag = false;
2485 }
2486 else
2487 {
2489 if (flag)
2490 {
2492 }
2493 string stringValue = _stringValue;
2494 if (stringValue != null)
2495 {
2497 _stringValue = null;
2498 }
2499 if (text != null)
2500 {
2501 string ns = _xnt.Add(ValueAsString(binXmlToken));
2502 PushNamespace(text, ns, implied: false);
2503 text = null;
2504 }
2505 flag = true;
2506 }
2507 }
2508 if (num != -1)
2509 {
2510 string attributeText = GetAttributeText(num);
2511 XmlSpace xmlSpace = XmlSpace.None;
2512 if (attributeText == "preserve")
2513 {
2514 xmlSpace = XmlSpace.Preserve;
2515 }
2516 else if (attributeText == "default")
2517 {
2518 xmlSpace = XmlSpace.Default;
2519 }
2520 _elementStack[_elemDepth].xmlSpace = xmlSpace;
2522 }
2523 if (num2 != -1)
2524 {
2526 }
2527 if (_attrCount < 200)
2528 {
2530 }
2531 else
2532 {
2534 }
2535 }
2536
2538 {
2539 for (int i = 0; i < _attrCount; i++)
2540 {
2541 _attributes[i].GetLocalnameAndNamespaceUri(out var localname, out var namespaceUri);
2542 for (int j = i + 1; j < _attrCount; j++)
2543 {
2544 if (_attributes[j].MatchNS(localname, namespaceUri))
2545 {
2547 }
2548 }
2549 }
2550 }
2551
2553 {
2554 int num;
2555 for (num = 256; num < _attrCount; num = checked(num * 2))
2556 {
2557 }
2558 if (_attrHashTbl.Length < num)
2559 {
2560 _attrHashTbl = new int[num];
2561 }
2562 for (int i = 0; i < _attrCount; i++)
2563 {
2564 string localname;
2565 string namespaceUri;
2567 int num2 = localnameAndNamespaceUriAndHash & (num - 1);
2568 int num3 = _attrHashTbl[num2];
2569 _attrHashTbl[num2] = i + 1;
2571 while (num3 != 0)
2572 {
2573 num3--;
2574 if (_attributes[num3].MatchHashNS(localnameAndNamespaceUriAndHash, localname, namespaceUri))
2575 {
2577 }
2579 }
2580 }
2581 Array.Clear(_attrHashTbl, 0, num);
2582 }
2583
2584 private string XmlDeclValue()
2585 {
2587 for (int i = 0; i < _attrCount; i++)
2588 {
2589 if (i > 0)
2590 {
2591 stringBuilder.Append(' ');
2592 }
2593 stringBuilder.Append(_attributes[i].name.localname);
2594 stringBuilder.Append("=\"");
2595 stringBuilder.Append(_attributes[i].val);
2596 stringBuilder.Append('"');
2597 }
2598 return stringBuilder.ToString();
2599 }
2600
2601 private string CDATAValue()
2602 {
2603 string text = GetString(_tokDataPos, _tokLen);
2605 while (PeekToken() == BinXmlToken.CData)
2606 {
2607 _pos++;
2608 if (stringBuilder == null)
2609 {
2610 stringBuilder = new StringBuilder(text.Length + text.Length / 2);
2611 stringBuilder.Append(text);
2612 }
2613 stringBuilder.Append(ParseText());
2614 }
2615 if (stringBuilder != null)
2616 {
2617 text = stringBuilder.ToString();
2618 }
2620 return text;
2621 }
2622
2623 private void FinishCDATA()
2624 {
2625 while (true)
2626 {
2627 switch (PeekToken())
2628 {
2629 case BinXmlToken.CData:
2630 break;
2631 case BinXmlToken.EndCData:
2632 _pos++;
2633 return;
2634 default:
2636 }
2637 _pos++;
2638 ScanText(out var _);
2639 }
2640 }
2641
2648
2649 private bool ReadDoc()
2650 {
2651 switch (_nodetype)
2652 {
2653 case XmlNodeType.CDATA:
2654 FinishCDATA();
2655 break;
2656 case XmlNodeType.EndElement:
2658 break;
2659 case XmlNodeType.Element:
2660 if (_isEmpty)
2661 {
2663 _isEmpty = false;
2664 }
2665 break;
2666 }
2667 while (true)
2668 {
2669 _nodetype = XmlNodeType.None;
2670 _mark = -1;
2671 if (_qnameOther.localname.Length != 0)
2672 {
2674 }
2676 _attrCount = 0;
2678 _stringValue = null;
2679 _hasTypedValue = false;
2680 _token = NextToken();
2681 switch (_token)
2682 {
2683 case BinXmlToken.EOF:
2684 if (_elemDepth > 0)
2685 {
2686 throw new XmlException(System.SR.Xml_UnexpectedEOF1, (string[])null);
2687 }
2688 _state = ScanState.EOF;
2689 return false;
2690 case BinXmlToken.Element:
2692 break;
2693 case BinXmlToken.EndElem:
2695 break;
2696 case BinXmlToken.DocType:
2698 if (_dtdProcessing == DtdProcessing.Ignore || _prevNameInfo != null)
2699 {
2700 continue;
2701 }
2702 break;
2703 case BinXmlToken.PI:
2704 ImplReadPI();
2705 if (_ignorePIs)
2706 {
2707 continue;
2708 }
2709 break;
2710 case BinXmlToken.Comment:
2712 if (_ignoreComments)
2713 {
2714 continue;
2715 }
2716 break;
2717 case BinXmlToken.CData:
2718 ImplReadCDATA();
2719 break;
2720 case BinXmlToken.Nest:
2721 ImplReadNest();
2722 _sniffed = false;
2723 return ReadInit(skipXmlDecl: true);
2724 case BinXmlToken.EndNest:
2725 if (_prevNameInfo != null)
2726 {
2728 return ReadDoc();
2729 }
2730 goto default;
2731 case BinXmlToken.XmlText:
2733 break;
2734 case BinXmlToken.SQL_SMALLINT:
2735 case BinXmlToken.SQL_INT:
2736 case BinXmlToken.SQL_REAL:
2737 case BinXmlToken.SQL_FLOAT:
2738 case BinXmlToken.SQL_MONEY:
2739 case BinXmlToken.SQL_BIT:
2740 case BinXmlToken.SQL_TINYINT:
2741 case BinXmlToken.SQL_BIGINT:
2742 case BinXmlToken.SQL_UUID:
2743 case BinXmlToken.SQL_DECIMAL:
2744 case BinXmlToken.SQL_NUMERIC:
2745 case BinXmlToken.SQL_BINARY:
2746 case BinXmlToken.SQL_CHAR:
2747 case BinXmlToken.SQL_NCHAR:
2748 case BinXmlToken.SQL_VARBINARY:
2749 case BinXmlToken.SQL_VARCHAR:
2750 case BinXmlToken.SQL_NVARCHAR:
2751 case BinXmlToken.SQL_DATETIME:
2752 case BinXmlToken.SQL_SMALLDATETIME:
2753 case BinXmlToken.SQL_SMALLMONEY:
2754 case BinXmlToken.SQL_TEXT:
2755 case BinXmlToken.SQL_IMAGE:
2756 case BinXmlToken.SQL_NTEXT:
2757 case BinXmlToken.SQL_UDT:
2758 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
2759 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
2760 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
2761 case BinXmlToken.XSD_KATMAI_TIME:
2762 case BinXmlToken.XSD_KATMAI_DATETIME:
2763 case BinXmlToken.XSD_KATMAI_DATE:
2764 case BinXmlToken.XSD_TIME:
2765 case BinXmlToken.XSD_DATETIME:
2766 case BinXmlToken.XSD_DATE:
2767 case BinXmlToken.XSD_BINHEX:
2768 case BinXmlToken.XSD_BASE64:
2769 case BinXmlToken.XSD_BOOLEAN:
2770 case BinXmlToken.XSD_DECIMAL:
2771 case BinXmlToken.XSD_BYTE:
2772 case BinXmlToken.XSD_UNSIGNEDSHORT:
2773 case BinXmlToken.XSD_UNSIGNEDINT:
2774 case BinXmlToken.XSD_UNSIGNEDLONG:
2775 case BinXmlToken.XSD_QNAME:
2777 if (XmlNodeType.Text == _nodetype)
2778 {
2780 }
2782 {
2783 continue;
2784 }
2785 return true;
2786 default:
2788 }
2789 break;
2790 }
2791 return true;
2792 }
2793
2794 private void ImplReadData(BinXmlToken tokenType)
2795 {
2796 _mark = _pos;
2797 switch (tokenType)
2798 {
2799 case BinXmlToken.SQL_CHAR:
2800 case BinXmlToken.SQL_NCHAR:
2801 case BinXmlToken.SQL_VARCHAR:
2802 case BinXmlToken.SQL_NVARCHAR:
2803 case BinXmlToken.SQL_TEXT:
2804 case BinXmlToken.SQL_NTEXT:
2806 _hasTypedValue = false;
2807 break;
2808 default:
2810 _hasTypedValue = true;
2811 break;
2812 }
2813 _nodetype = ScanOverValue(_token, attr: false, checkChars: true);
2814 switch (PeekNextToken())
2815 {
2816 case BinXmlToken.SQL_SMALLINT:
2817 case BinXmlToken.SQL_INT:
2818 case BinXmlToken.SQL_REAL:
2819 case BinXmlToken.SQL_FLOAT:
2820 case BinXmlToken.SQL_MONEY:
2821 case BinXmlToken.SQL_BIT:
2822 case BinXmlToken.SQL_TINYINT:
2823 case BinXmlToken.SQL_BIGINT:
2824 case BinXmlToken.SQL_UUID:
2825 case BinXmlToken.SQL_DECIMAL:
2826 case BinXmlToken.SQL_NUMERIC:
2827 case BinXmlToken.SQL_BINARY:
2828 case BinXmlToken.SQL_CHAR:
2829 case BinXmlToken.SQL_NCHAR:
2830 case BinXmlToken.SQL_VARBINARY:
2831 case BinXmlToken.SQL_VARCHAR:
2832 case BinXmlToken.SQL_NVARCHAR:
2833 case BinXmlToken.SQL_DATETIME:
2834 case BinXmlToken.SQL_SMALLDATETIME:
2835 case BinXmlToken.SQL_SMALLMONEY:
2836 case BinXmlToken.SQL_TEXT:
2837 case BinXmlToken.SQL_IMAGE:
2838 case BinXmlToken.SQL_NTEXT:
2839 case BinXmlToken.SQL_UDT:
2840 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
2841 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
2842 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
2843 case BinXmlToken.XSD_KATMAI_TIME:
2844 case BinXmlToken.XSD_KATMAI_DATETIME:
2845 case BinXmlToken.XSD_KATMAI_DATE:
2846 case BinXmlToken.XSD_TIME:
2847 case BinXmlToken.XSD_DATETIME:
2848 case BinXmlToken.XSD_DATE:
2849 case BinXmlToken.XSD_BINHEX:
2850 case BinXmlToken.XSD_BASE64:
2851 case BinXmlToken.XSD_BOOLEAN:
2852 case BinXmlToken.XSD_DECIMAL:
2853 case BinXmlToken.XSD_BYTE:
2854 case BinXmlToken.XSD_UNSIGNEDSHORT:
2855 case BinXmlToken.XSD_UNSIGNEDINT:
2856 case BinXmlToken.XSD_UNSIGNEDLONG:
2857 case BinXmlToken.XSD_QNAME:
2859 }
2860 }
2861
2862 private void ImplReadElement()
2863 {
2864 if (3 != _docState || 9 != _docState)
2865 {
2866 switch (_docState)
2867 {
2868 case 0:
2869 _docState = 9;
2870 break;
2871 case 1:
2872 case 2:
2873 _docState = 3;
2874 break;
2875 case -1:
2877 }
2878 }
2879 _elemDepth++;
2880 if (_elemDepth == _elementStack.Length)
2881 {
2882 GrowElements();
2883 }
2887 PushNamespace(qName.prefix, qName.namespaceUri, implied: true);
2889 if (BinXmlToken.Attr == binXmlToken)
2890 {
2893 }
2895 if (BinXmlToken.EndElem == binXmlToken)
2896 {
2897 NextToken();
2898 _isEmpty = true;
2899 }
2900 else if (BinXmlToken.SQL_NVARCHAR == binXmlToken)
2901 {
2902 if (_mark < 0)
2903 {
2904 _mark = _pos;
2905 }
2906 _pos++;
2907 if (ReadByte() == 0)
2908 {
2909 if (247 != ReadByte())
2910 {
2911 _pos -= 3;
2912 }
2913 else
2914 {
2915 _pos--;
2916 }
2917 }
2918 else
2919 {
2920 _pos -= 2;
2921 }
2922 }
2923 _nodetype = XmlNodeType.Element;
2926 }
2927
2928 private void ImplReadEndElement()
2929 {
2930 if (_elemDepth == 0)
2931 {
2933 }
2934 int elemDepth = _elemDepth;
2935 if (1 == elemDepth && 3 == _docState)
2936 {
2937 _docState = -1;
2938 }
2941 _nodetype = XmlNodeType.EndElement;
2942 }
2943
2944 private void ImplReadDoctype()
2945 {
2946 if (_dtdProcessing == DtdProcessing.Prohibit)
2947 {
2949 }
2950 switch (_docState)
2951 {
2952 case 9:
2954 default:
2956 case 0:
2957 case 1:
2958 _docState = 2;
2960 if (BinXmlToken.System == PeekToken())
2961 {
2962 _pos++;
2963 _attributes[_attrCount++].Set(new QName(string.Empty, _xnt.Add("SYSTEM"), string.Empty), ParseText());
2964 }
2965 if (BinXmlToken.Public == PeekToken())
2966 {
2967 _pos++;
2968 _attributes[_attrCount++].Set(new QName(string.Empty, _xnt.Add("PUBLIC"), string.Empty), ParseText());
2969 }
2970 if (BinXmlToken.Subset == PeekToken())
2971 {
2972 _pos++;
2973 _mark = _pos;
2975 }
2976 else
2977 {
2978 _tokLen = (_tokDataPos = 0);
2979 }
2980 _nodetype = XmlNodeType.DocumentType;
2982 break;
2983 }
2984 }
2985
2986 private void ImplReadPI()
2987 {
2989 _mark = _pos;
2991 _nodetype = XmlNodeType.ProcessingInstruction;
2992 }
2993
2994 private void ImplReadComment()
2995 {
2996 _nodetype = XmlNodeType.Comment;
2997 _mark = _pos;
2999 }
3000
3001 private void ImplReadCDATA()
3002 {
3004 _nodetype = XmlNodeType.CDATA;
3005 _mark = _pos;
3007 }
3008
3009 private void ImplReadNest()
3010 {
3014 _docState = 0;
3015 }
3016
3017 private void ImplReadEndNest()
3018 {
3020 _symbolTables = prevNameInfo.symbolTables;
3021 _docState = prevNameInfo.docState;
3023 }
3024
3025 private void ImplReadXmlText()
3026 {
3028 string xmlFragment = ParseText();
3031 {
3032 if (value.scope > 0)
3033 {
3034 xmlNamespaceManager.AddNamespace(value.prefix, value.uri);
3035 }
3036 }
3037 XmlReaderSettings settings = Settings;
3038 settings.ReadOnly = false;
3041 if (_elemDepth != 0)
3042 {
3044 }
3045 settings.ReadOnly = true;
3047 _textXmlReader = new XmlTextReaderImpl(xmlFragment, context, settings);
3048 if (!_textXmlReader.Read() || (_textXmlReader.NodeType == XmlNodeType.XmlDeclaration && !_textXmlReader.Read()))
3049 {
3050 _state = ScanState.Doc;
3051 ReadDoc();
3052 }
3053 else
3054 {
3055 _state = ScanState.XmlText;
3057 }
3058 }
3059
3061 {
3063 _nodetype = textXmlReader.NodeType;
3067 _valueType = textXmlReader.ValueType;
3068 _isEmpty = textXmlReader.IsEmptyElement;
3069 }
3070
3072 {
3073 if (needUpdate)
3074 {
3076 }
3077 return needUpdate;
3078 }
3079
3080 private void CheckAllowContent()
3081 {
3082 switch (_docState)
3083 {
3084 case 0:
3085 _docState = 9;
3086 break;
3087 default:
3089 case 3:
3090 case 9:
3091 break;
3092 }
3093 }
3094
3096 {
3097 Type[] array = new Type[256];
3098 array[134] = typeof(bool);
3099 array[7] = typeof(byte);
3100 array[136] = typeof(sbyte);
3101 array[1] = typeof(short);
3102 array[137] = typeof(ushort);
3103 array[138] = typeof(uint);
3104 array[3] = typeof(float);
3105 array[4] = typeof(double);
3106 array[8] = typeof(long);
3107 array[139] = typeof(ulong);
3109 array[2] = (array[6] = typeof(int));
3110 array[135] = (array[11] = (array[10] = (array[5] = (array[20] = typeof(decimal)))));
3111 array[125] = (array[126] = (array[127] = (array[131] = (array[130] = (array[129] = (array[18] = (array[19] = typeof(DateTime))))))));
3112 array[122] = (array[123] = (array[124] = typeof(DateTimeOffset)));
3113 array[133] = (array[132] = (array[27] = (array[23] = (array[12] = (array[15] = typeof(byte[]))))));
3114 array[13] = TypeOfString;
3115 array[16] = TypeOfString;
3116 array[22] = TypeOfString;
3117 array[14] = TypeOfString;
3118 array[17] = TypeOfString;
3119 array[24] = TypeOfString;
3120 array[9] = TypeOfString;
3121 return array;
3122 }
3123
3125 {
3126 Type type = s_tokenTypeMap[(int)token];
3127 if (type == null)
3128 {
3129 throw ThrowUnexpectedToken(token);
3130 }
3131 return type;
3132 }
3133
3134 private void ReScanOverValue(BinXmlToken token)
3135 {
3136 ScanOverValue(token, attr: true, checkChars: false);
3137 }
3138
3140 {
3141 checked
3142 {
3143 if (token == BinXmlToken.SQL_NVARCHAR)
3144 {
3145 if (_mark < 0)
3146 {
3147 _mark = _pos;
3148 }
3149 _tokLen = ParseMB32();
3150 _tokDataPos = _pos;
3151 _pos += _tokLen * 2;
3152 Fill(-1);
3154 {
3155 return CheckText(attr);
3156 }
3157 if (!attr)
3158 {
3159 return CheckTextIsWS();
3160 }
3161 return XmlNodeType.Text;
3162 }
3163 return ScanOverAnyValue(token, attr, checkChars);
3164 }
3165 }
3166
3168 {
3169 if (_mark < 0)
3170 {
3171 _mark = _pos;
3172 }
3173 checked
3174 {
3175 switch (token)
3176 {
3177 case BinXmlToken.SQL_BIT:
3178 case BinXmlToken.SQL_TINYINT:
3179 case BinXmlToken.XSD_BOOLEAN:
3180 case BinXmlToken.XSD_BYTE:
3181 _tokDataPos = _pos;
3182 _tokLen = 1;
3183 _pos++;
3184 break;
3185 case BinXmlToken.SQL_SMALLINT:
3186 case BinXmlToken.XSD_UNSIGNEDSHORT:
3187 _tokDataPos = _pos;
3188 _tokLen = 2;
3189 _pos += 2;
3190 break;
3191 case BinXmlToken.SQL_INT:
3192 case BinXmlToken.SQL_REAL:
3193 case BinXmlToken.SQL_SMALLDATETIME:
3194 case BinXmlToken.SQL_SMALLMONEY:
3195 case BinXmlToken.XSD_UNSIGNEDINT:
3196 _tokDataPos = _pos;
3197 _tokLen = 4;
3198 _pos += 4;
3199 break;
3200 case BinXmlToken.SQL_FLOAT:
3201 case BinXmlToken.SQL_MONEY:
3202 case BinXmlToken.SQL_BIGINT:
3203 case BinXmlToken.SQL_DATETIME:
3204 case BinXmlToken.XSD_TIME:
3205 case BinXmlToken.XSD_DATETIME:
3206 case BinXmlToken.XSD_DATE:
3207 case BinXmlToken.XSD_UNSIGNEDLONG:
3208 _tokDataPos = _pos;
3209 _tokLen = 8;
3210 _pos += 8;
3211 break;
3212 case BinXmlToken.SQL_UUID:
3213 _tokDataPos = _pos;
3214 _tokLen = 16;
3215 _pos += 16;
3216 break;
3217 case BinXmlToken.SQL_DECIMAL:
3218 case BinXmlToken.SQL_NUMERIC:
3219 case BinXmlToken.XSD_DECIMAL:
3220 _tokDataPos = _pos;
3221 _tokLen = ParseMB64();
3222 _pos += _tokLen;
3223 break;
3224 case BinXmlToken.SQL_BINARY:
3225 case BinXmlToken.SQL_VARBINARY:
3226 case BinXmlToken.SQL_IMAGE:
3227 case BinXmlToken.SQL_UDT:
3228 case BinXmlToken.XSD_BINHEX:
3229 case BinXmlToken.XSD_BASE64:
3230 _tokLen = ParseMB64();
3231 _tokDataPos = _pos;
3232 _pos += _tokLen;
3233 break;
3234 case BinXmlToken.SQL_CHAR:
3235 case BinXmlToken.SQL_VARCHAR:
3236 case BinXmlToken.SQL_TEXT:
3237 _tokLen = ParseMB64();
3238 _tokDataPos = _pos;
3239 _pos += _tokLen;
3241 {
3242 Fill(-1);
3243 string text = ValueAsString(token);
3244 XmlConvert.VerifyCharData(text, ExceptionType.ArgumentException, ExceptionType.XmlException);
3246 }
3247 break;
3248 case BinXmlToken.SQL_NCHAR:
3249 case BinXmlToken.SQL_NVARCHAR:
3250 case BinXmlToken.SQL_NTEXT:
3251 return ScanOverValue(BinXmlToken.SQL_NVARCHAR, attr, checkChars);
3252 case BinXmlToken.XSD_QNAME:
3253 _tokDataPos = _pos;
3254 ParseMB32();
3255 break;
3256 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
3257 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
3258 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
3259 case BinXmlToken.XSD_KATMAI_TIME:
3260 case BinXmlToken.XSD_KATMAI_DATETIME:
3261 case BinXmlToken.XSD_KATMAI_DATE:
3262 VerifyVersion(2, token);
3263 _tokDataPos = _pos;
3265 _pos += _tokLen;
3266 break;
3267 default:
3268 throw ThrowUnexpectedToken(token);
3269 }
3270 Fill(-1);
3271 return XmlNodeType.Text;
3272 }
3273 }
3274
3276 {
3278 if (!attr)
3279 {
3280 while (true)
3281 {
3283 {
3284 if (!_xmlspacePreserve)
3285 {
3286 return XmlNodeType.Whitespace;
3287 }
3288 return XmlNodeType.SignificantWhitespace;
3289 }
3290 if (value > 255 || !XmlCharType.IsWhiteSpace((char)value))
3291 {
3292 break;
3293 }
3294 source = source.Slice(2);
3295 }
3296 }
3297 char c;
3298 ushort value3;
3299 while (true)
3300 {
3302 {
3303 return XmlNodeType.Text;
3304 }
3305 source = source.Slice(2);
3306 c = (char)value2;
3307 if (!XmlCharType.IsCharData(c))
3308 {
3310 {
3311 throw XmlConvert.CreateInvalidCharException(c, '\0', ExceptionType.XmlException);
3312 }
3314 {
3316 }
3318 {
3319 break;
3320 }
3321 source = source.Slice(2);
3322 }
3323 }
3325 }
3326
3328 {
3329 byte[] data = _data;
3330 int num = _tokDataPos;
3331 while (true)
3332 {
3333 if (num < _pos)
3334 {
3335 if (data[num + 1] != 0)
3336 {
3337 break;
3338 }
3339 byte b = data[num];
3340 if ((uint)(b - 9) > 1u && b != 13 && b != 32)
3341 {
3342 break;
3343 }
3344 num += 2;
3345 continue;
3346 }
3348 {
3349 return XmlNodeType.SignificantWhitespace;
3350 }
3351 return XmlNodeType.Whitespace;
3352 }
3353 return XmlNodeType.Text;
3354 }
3355
3357 {
3358 if (_end - _tokDataPos < _tokLen)
3359 {
3361 }
3362 }
3363
3365 {
3366 switch (token)
3367 {
3368 case BinXmlToken.XSD_KATMAI_DATE:
3369 return 3;
3370 case BinXmlToken.XSD_KATMAI_TIME:
3371 case BinXmlToken.XSD_KATMAI_DATETIME:
3372 {
3373 Fill(0);
3374 byte scale = _data[_pos];
3375 return 4 + XsdKatmaiTimeScaleToValueLength(scale);
3376 }
3377 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
3378 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
3379 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
3380 {
3381 Fill(0);
3382 byte scale = _data[_pos];
3383 return 6 + XsdKatmaiTimeScaleToValueLength(scale);
3384 }
3385 default:
3387 }
3388 }
3389
3390 private int XsdKatmaiTimeScaleToValueLength(byte scale)
3391 {
3392 if (scale > 7)
3393 {
3394 throw new XmlException(System.SR.SqlTypes_ArithOverflow, (string)null);
3395 }
3397 }
3398
3399 private long ValueAsLong()
3400 {
3402 switch (_token)
3403 {
3404 case BinXmlToken.SQL_BIT:
3405 case BinXmlToken.SQL_TINYINT:
3406 {
3407 byte b2 = _data[_tokDataPos];
3408 return b2;
3409 }
3410 case BinXmlToken.XSD_BYTE:
3411 {
3412 sbyte b = (sbyte)_data[_tokDataPos];
3413 return b;
3414 }
3415 case BinXmlToken.SQL_SMALLINT:
3416 return GetInt16(_tokDataPos);
3417 case BinXmlToken.SQL_INT:
3418 return GetInt32(_tokDataPos);
3419 case BinXmlToken.SQL_BIGINT:
3420 return GetInt64(_tokDataPos);
3421 case BinXmlToken.XSD_UNSIGNEDSHORT:
3422 return GetUInt16(_tokDataPos);
3423 case BinXmlToken.XSD_UNSIGNEDINT:
3424 return GetUInt32(_tokDataPos);
3425 case BinXmlToken.XSD_UNSIGNEDLONG:
3426 {
3427 ulong uInt = GetUInt64(_tokDataPos);
3428 return checked((long)uInt);
3429 }
3430 case BinXmlToken.SQL_REAL:
3431 case BinXmlToken.SQL_FLOAT:
3432 {
3433 double num2 = ValueAsDouble();
3434 return (long)num2;
3435 }
3436 case BinXmlToken.SQL_MONEY:
3437 case BinXmlToken.SQL_DECIMAL:
3438 case BinXmlToken.SQL_NUMERIC:
3439 case BinXmlToken.SQL_SMALLMONEY:
3440 case BinXmlToken.XSD_DECIMAL:
3441 {
3442 decimal num = ValueAsDecimal();
3443 return (long)num;
3444 }
3445 default:
3447 }
3448 }
3449
3450 private ulong ValueAsULong()
3451 {
3452 if (BinXmlToken.XSD_UNSIGNEDLONG == _token)
3453 {
3455 return GetUInt64(_tokDataPos);
3456 }
3458 }
3459
3460 private decimal ValueAsDecimal()
3461 {
3463 switch (_token)
3464 {
3465 case BinXmlToken.SQL_SMALLINT:
3466 case BinXmlToken.SQL_INT:
3467 case BinXmlToken.SQL_BIT:
3468 case BinXmlToken.SQL_TINYINT:
3469 case BinXmlToken.SQL_BIGINT:
3470 case BinXmlToken.XSD_BYTE:
3471 case BinXmlToken.XSD_UNSIGNEDSHORT:
3472 case BinXmlToken.XSD_UNSIGNEDINT:
3473 return new decimal(ValueAsLong());
3474 case BinXmlToken.XSD_UNSIGNEDLONG:
3475 return new decimal(ValueAsULong());
3476 case BinXmlToken.SQL_REAL:
3477 return new decimal(GetSingle(_tokDataPos));
3478 case BinXmlToken.SQL_FLOAT:
3479 return new decimal(GetDouble(_tokDataPos));
3480 case BinXmlToken.SQL_SMALLMONEY:
3482 case BinXmlToken.SQL_MONEY:
3484 case BinXmlToken.SQL_DECIMAL:
3485 case BinXmlToken.SQL_NUMERIC:
3486 case BinXmlToken.XSD_DECIMAL:
3487 return new BinXmlSqlDecimal(_data, _tokDataPos, _token == BinXmlToken.XSD_DECIMAL).ToDecimal();
3488 default:
3490 }
3491 }
3492
3493 private double ValueAsDouble()
3494 {
3496 switch (_token)
3497 {
3498 case BinXmlToken.SQL_SMALLINT:
3499 case BinXmlToken.SQL_INT:
3500 case BinXmlToken.SQL_BIT:
3501 case BinXmlToken.SQL_TINYINT:
3502 case BinXmlToken.SQL_BIGINT:
3503 case BinXmlToken.XSD_BYTE:
3504 case BinXmlToken.XSD_UNSIGNEDSHORT:
3505 case BinXmlToken.XSD_UNSIGNEDINT:
3506 return ValueAsLong();
3507 case BinXmlToken.XSD_UNSIGNEDLONG:
3508 return ValueAsULong();
3509 case BinXmlToken.SQL_REAL:
3510 return GetSingle(_tokDataPos);
3511 case BinXmlToken.SQL_FLOAT:
3512 return GetDouble(_tokDataPos);
3513 case BinXmlToken.SQL_MONEY:
3514 case BinXmlToken.SQL_DECIMAL:
3515 case BinXmlToken.SQL_NUMERIC:
3516 case BinXmlToken.SQL_SMALLMONEY:
3517 case BinXmlToken.XSD_DECIMAL:
3518 return (double)ValueAsDecimal();
3519 default:
3521 }
3522 }
3523
3525 {
3527 switch (_token)
3528 {
3529 case BinXmlToken.SQL_DATETIME:
3530 {
3532 int int5 = GetInt32(tokDataPos2);
3533 uint uInt2 = GetUInt32(tokDataPos2 + 4);
3535 }
3536 case BinXmlToken.SQL_SMALLDATETIME:
3537 {
3538 int tokDataPos = _tokDataPos;
3539 short int4 = GetInt16(tokDataPos);
3540 ushort uInt = GetUInt16(tokDataPos + 2);
3542 }
3543 case BinXmlToken.XSD_TIME:
3544 {
3545 long int3 = GetInt64(_tokDataPos);
3547 }
3548 case BinXmlToken.XSD_DATE:
3549 {
3550 long int2 = GetInt64(_tokDataPos);
3552 }
3553 case BinXmlToken.XSD_DATETIME:
3554 {
3555 long @int = GetInt64(_tokDataPos);
3557 }
3558 case BinXmlToken.XSD_KATMAI_DATE:
3560 case BinXmlToken.XSD_KATMAI_DATETIME:
3562 case BinXmlToken.XSD_KATMAI_TIME:
3564 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
3566 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
3568 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
3570 default:
3572 }
3573 }
3574
3586
3587 private string ValueAsDateTimeString()
3588 {
3590 switch (_token)
3591 {
3592 case BinXmlToken.SQL_DATETIME:
3593 {
3595 int int5 = GetInt32(tokDataPos2);
3596 uint uInt2 = GetUInt32(tokDataPos2 + 4);
3598 }
3599 case BinXmlToken.SQL_SMALLDATETIME:
3600 {
3601 int tokDataPos = _tokDataPos;
3602 short int4 = GetInt16(tokDataPos);
3603 ushort uInt = GetUInt16(tokDataPos + 2);
3605 }
3606 case BinXmlToken.XSD_TIME:
3607 {
3608 long int3 = GetInt64(_tokDataPos);
3610 }
3611 case BinXmlToken.XSD_DATE:
3612 {
3613 long int2 = GetInt64(_tokDataPos);
3615 }
3616 case BinXmlToken.XSD_DATETIME:
3617 {
3618 long @int = GetInt64(_tokDataPos);
3620 }
3621 case BinXmlToken.XSD_KATMAI_DATE:
3623 case BinXmlToken.XSD_KATMAI_DATETIME:
3625 case BinXmlToken.XSD_KATMAI_TIME:
3627 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
3629 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
3631 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
3633 default:
3635 }
3636 }
3637
3638 private string ValueAsString(BinXmlToken token)
3639 {
3640 try
3641 {
3643 switch (token)
3644 {
3645 case BinXmlToken.SQL_NCHAR:
3646 case BinXmlToken.SQL_NVARCHAR:
3647 case BinXmlToken.SQL_NTEXT:
3648 return GetString(_tokDataPos, _tokLen);
3649 case BinXmlToken.XSD_BOOLEAN:
3650 if (_data[_tokDataPos] == 0)
3651 {
3652 return "false";
3653 }
3654 return "true";
3655 case BinXmlToken.SQL_SMALLINT:
3656 case BinXmlToken.SQL_INT:
3657 case BinXmlToken.SQL_BIT:
3658 case BinXmlToken.SQL_TINYINT:
3659 case BinXmlToken.SQL_BIGINT:
3660 case BinXmlToken.XSD_BYTE:
3661 case BinXmlToken.XSD_UNSIGNEDSHORT:
3662 case BinXmlToken.XSD_UNSIGNEDINT:
3663 return ValueAsLong().ToString(CultureInfo.InvariantCulture);
3664 case BinXmlToken.XSD_UNSIGNEDLONG:
3665 return ValueAsULong().ToString(CultureInfo.InvariantCulture);
3666 case BinXmlToken.SQL_REAL:
3668 case BinXmlToken.SQL_FLOAT:
3670 case BinXmlToken.SQL_UUID:
3671 {
3673 int int2 = GetInt32(tokDataPos2);
3674 short int3 = GetInt16(tokDataPos2 + 4);
3675 short int4 = GetInt16(tokDataPos2 + 6);
3676 return new Guid(int2, int3, int4, _data[tokDataPos2 + 8], _data[tokDataPos2 + 9], _data[tokDataPos2 + 10], _data[tokDataPos2 + 11], _data[tokDataPos2 + 12], _data[tokDataPos2 + 13], _data[tokDataPos2 + 14], _data[tokDataPos2 + 15]).ToString();
3677 }
3678 case BinXmlToken.SQL_SMALLMONEY:
3680 case BinXmlToken.SQL_MONEY:
3682 case BinXmlToken.SQL_DECIMAL:
3683 case BinXmlToken.SQL_NUMERIC:
3684 case BinXmlToken.XSD_DECIMAL:
3685 return new BinXmlSqlDecimal(_data, _tokDataPos, token == BinXmlToken.XSD_DECIMAL).ToString();
3686 case BinXmlToken.SQL_CHAR:
3687 case BinXmlToken.SQL_VARCHAR:
3688 case BinXmlToken.SQL_TEXT:
3689 {
3690 int tokDataPos = _tokDataPos;
3691 int @int = GetInt32(tokDataPos);
3692 Encoding encoding = Encoding.GetEncoding(@int);
3693 return encoding.GetString(_data, tokDataPos + 4, _tokLen - 4);
3694 }
3695 case BinXmlToken.SQL_BINARY:
3696 case BinXmlToken.SQL_VARBINARY:
3697 case BinXmlToken.SQL_IMAGE:
3698 case BinXmlToken.SQL_UDT:
3699 case BinXmlToken.XSD_BASE64:
3701 case BinXmlToken.XSD_BINHEX:
3703 case BinXmlToken.SQL_DATETIME:
3704 case BinXmlToken.SQL_SMALLDATETIME:
3705 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
3706 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
3707 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
3708 case BinXmlToken.XSD_KATMAI_TIME:
3709 case BinXmlToken.XSD_KATMAI_DATETIME:
3710 case BinXmlToken.XSD_KATMAI_DATE:
3711 case BinXmlToken.XSD_TIME:
3712 case BinXmlToken.XSD_DATETIME:
3713 case BinXmlToken.XSD_DATE:
3714 return ValueAsDateTimeString();
3715 case BinXmlToken.XSD_QNAME:
3716 {
3717 int num = ParseMB32(_tokDataPos);
3719 {
3720 throw new XmlException(System.SR.XmlBin_InvalidQNameID, string.Empty);
3721 }
3723 if (qName.prefix.Length == 0)
3724 {
3725 return qName.localname;
3726 }
3727 return qName.prefix + ":" + qName.localname;
3728 }
3729 default:
3731 }
3732 }
3733 catch
3734 {
3735 _state = ScanState.Error;
3736 throw;
3737 }
3738 }
3739
3741 {
3743 switch (token)
3744 {
3745 case BinXmlToken.SQL_NCHAR:
3746 case BinXmlToken.SQL_NVARCHAR:
3747 case BinXmlToken.SQL_NTEXT:
3748 return GetString(_tokDataPos, _tokLen);
3749 case BinXmlToken.XSD_BOOLEAN:
3750 return _data[_tokDataPos] != 0;
3751 case BinXmlToken.SQL_BIT:
3752 return (int)_data[_tokDataPos];
3753 case BinXmlToken.SQL_TINYINT:
3754 return _data[_tokDataPos];
3755 case BinXmlToken.SQL_SMALLINT:
3756 return GetInt16(_tokDataPos);
3757 case BinXmlToken.SQL_INT:
3758 return GetInt32(_tokDataPos);
3759 case BinXmlToken.SQL_BIGINT:
3760 return GetInt64(_tokDataPos);
3761 case BinXmlToken.XSD_BYTE:
3762 {
3763 sbyte b = (sbyte)_data[_tokDataPos];
3764 return b;
3765 }
3766 case BinXmlToken.XSD_UNSIGNEDSHORT:
3767 return GetUInt16(_tokDataPos);
3768 case BinXmlToken.XSD_UNSIGNEDINT:
3769 return GetUInt32(_tokDataPos);
3770 case BinXmlToken.XSD_UNSIGNEDLONG:
3771 return GetUInt64(_tokDataPos);
3772 case BinXmlToken.SQL_REAL:
3773 return GetSingle(_tokDataPos);
3774 case BinXmlToken.SQL_FLOAT:
3775 return GetDouble(_tokDataPos);
3776 case BinXmlToken.SQL_UUID:
3777 {
3779 int int2 = GetInt32(tokDataPos2);
3780 short int3 = GetInt16(tokDataPos2 + 4);
3781 short int4 = GetInt16(tokDataPos2 + 6);
3782 return new Guid(int2, int3, int4, _data[tokDataPos2 + 8], _data[tokDataPos2 + 9], _data[tokDataPos2 + 10], _data[tokDataPos2 + 11], _data[tokDataPos2 + 12], _data[tokDataPos2 + 13], _data[tokDataPos2 + 14], _data[tokDataPos2 + 15]).ToString();
3783 }
3784 case BinXmlToken.SQL_SMALLMONEY:
3785 {
3788 {
3789 return binXmlSqlMoney2;
3790 }
3791 return binXmlSqlMoney2.ToDecimal();
3792 }
3793 case BinXmlToken.SQL_MONEY:
3794 {
3797 {
3798 return binXmlSqlMoney;
3799 }
3800 return binXmlSqlMoney.ToDecimal();
3801 }
3802 case BinXmlToken.SQL_DECIMAL:
3803 case BinXmlToken.SQL_NUMERIC:
3804 case BinXmlToken.XSD_DECIMAL:
3805 {
3808 {
3809 return binXmlSqlDecimal;
3810 }
3811 return binXmlSqlDecimal.ToDecimal();
3812 }
3813 case BinXmlToken.SQL_CHAR:
3814 case BinXmlToken.SQL_VARCHAR:
3815 case BinXmlToken.SQL_TEXT:
3816 {
3817 int tokDataPos = _tokDataPos;
3818 int @int = GetInt32(tokDataPos);
3819 Encoding encoding = Encoding.GetEncoding(@int);
3820 return encoding.GetString(_data, tokDataPos + 4, _tokLen - 4);
3821 }
3822 case BinXmlToken.SQL_BINARY:
3823 case BinXmlToken.SQL_VARBINARY:
3824 case BinXmlToken.SQL_IMAGE:
3825 case BinXmlToken.SQL_UDT:
3826 case BinXmlToken.XSD_BINHEX:
3827 case BinXmlToken.XSD_BASE64:
3828 {
3829 byte[] array = new byte[_tokLen];
3831 return array;
3832 }
3833 case BinXmlToken.SQL_DATETIME:
3834 case BinXmlToken.SQL_SMALLDATETIME:
3835 case BinXmlToken.XSD_KATMAI_TIME:
3836 case BinXmlToken.XSD_KATMAI_DATETIME:
3837 case BinXmlToken.XSD_KATMAI_DATE:
3838 case BinXmlToken.XSD_TIME:
3839 case BinXmlToken.XSD_DATETIME:
3840 case BinXmlToken.XSD_DATE:
3841 return ValueAsDateTime();
3842 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
3843 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
3844 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
3845 return ValueAsDateTimeOffset();
3846 case BinXmlToken.XSD_QNAME:
3847 {
3848 int num = ParseMB32(_tokDataPos);
3850 {
3851 throw new XmlException(System.SR.XmlBin_InvalidQNameID, string.Empty);
3852 }
3854 return new XmlQualifiedName(qName.localname, qName.namespaceUri);
3855 }
3856 default:
3858 }
3859 }
3860
3866
3868 {
3870 switch (token)
3871 {
3872 case BinXmlToken.SQL_NCHAR:
3873 case BinXmlToken.SQL_NVARCHAR:
3874 case BinXmlToken.SQL_NTEXT:
3876 case BinXmlToken.XSD_BOOLEAN:
3878 case BinXmlToken.SQL_BIT:
3880 case BinXmlToken.SQL_TINYINT:
3882 case BinXmlToken.SQL_SMALLINT:
3883 {
3884 int @int = GetInt16(_tokDataPos);
3886 }
3887 case BinXmlToken.SQL_INT:
3888 {
3889 int int2 = GetInt32(_tokDataPos);
3891 }
3892 case BinXmlToken.SQL_BIGINT:
3893 {
3894 long int4 = GetInt64(_tokDataPos);
3896 }
3897 case BinXmlToken.XSD_BYTE:
3899 case BinXmlToken.XSD_UNSIGNEDSHORT:
3900 {
3901 int uInt = GetUInt16(_tokDataPos);
3903 }
3904 case BinXmlToken.XSD_UNSIGNEDINT:
3905 {
3906 long num3 = GetUInt32(_tokDataPos);
3908 }
3909 case BinXmlToken.XSD_UNSIGNEDLONG:
3910 {
3911 decimal num2 = GetUInt64(_tokDataPos);
3913 }
3914 case BinXmlToken.SQL_REAL:
3915 {
3916 float single = GetSingle(_tokDataPos);
3918 }
3919 case BinXmlToken.SQL_FLOAT:
3920 {
3921 double @double = GetDouble(_tokDataPos);
3923 }
3924 case BinXmlToken.SQL_UUID:
3926 case BinXmlToken.SQL_SMALLMONEY:
3928 case BinXmlToken.SQL_MONEY:
3930 case BinXmlToken.SQL_DECIMAL:
3931 case BinXmlToken.SQL_NUMERIC:
3932 case BinXmlToken.XSD_DECIMAL:
3934 case BinXmlToken.SQL_CHAR:
3935 case BinXmlToken.SQL_VARCHAR:
3936 case BinXmlToken.SQL_TEXT:
3937 {
3938 int tokDataPos = _tokDataPos;
3939 int int3 = GetInt32(tokDataPos);
3940 Encoding encoding = Encoding.GetEncoding(int3);
3942 }
3943 case BinXmlToken.SQL_BINARY:
3944 case BinXmlToken.SQL_VARBINARY:
3945 case BinXmlToken.SQL_IMAGE:
3946 case BinXmlToken.SQL_UDT:
3947 case BinXmlToken.XSD_BINHEX:
3948 case BinXmlToken.XSD_BASE64:
3949 {
3950 byte[] array = new byte[_tokLen];
3952 return GetValueConverter((token == BinXmlToken.XSD_BINHEX) ? XmlTypeCode.HexBinary : XmlTypeCode.Base64Binary).ChangeType(array, returnType, namespaceResolver);
3953 }
3954 case BinXmlToken.SQL_DATETIME:
3955 case BinXmlToken.SQL_SMALLDATETIME:
3956 case BinXmlToken.XSD_KATMAI_TIME:
3957 case BinXmlToken.XSD_KATMAI_DATETIME:
3958 case BinXmlToken.XSD_KATMAI_DATE:
3959 case BinXmlToken.XSD_DATETIME:
3961 case BinXmlToken.XSD_KATMAI_TIMEOFFSET:
3962 case BinXmlToken.XSD_KATMAI_DATETIMEOFFSET:
3963 case BinXmlToken.XSD_KATMAI_DATEOFFSET:
3965 case BinXmlToken.XSD_TIME:
3967 case BinXmlToken.XSD_DATE:
3969 case BinXmlToken.XSD_QNAME:
3970 {
3971 int num = ParseMB32(_tokDataPos);
3973 {
3974 throw new XmlException(System.SR.XmlBin_InvalidQNameID, string.Empty);
3975 }
3978 }
3979 default:
3981 }
3982 }
3983
3984 private short GetInt16(int pos)
3985 {
3986 return BinaryPrimitives.ReadInt16LittleEndian(_data.AsSpan(pos));
3987 }
3988
3989 private ushort GetUInt16(int pos)
3990 {
3991 return BinaryPrimitives.ReadUInt16LittleEndian(_data.AsSpan(pos));
3992 }
3993
3994 private int GetInt32(int pos)
3995 {
3996 return BinaryPrimitives.ReadInt32LittleEndian(_data.AsSpan(pos));
3997 }
3998
3999 private uint GetUInt32(int pos)
4000 {
4001 return BinaryPrimitives.ReadUInt32LittleEndian(_data.AsSpan(pos));
4002 }
4003
4004 private long GetInt64(int pos)
4005 {
4006 return BinaryPrimitives.ReadInt64LittleEndian(_data.AsSpan(pos));
4007 }
4008
4009 private ulong GetUInt64(int pos)
4010 {
4011 return BinaryPrimitives.ReadUInt64LittleEndian(_data.AsSpan(pos));
4012 }
4013
4014 private float GetSingle(int offset)
4015 {
4017 }
4018
4019 private double GetDouble(int offset)
4020 {
4022 }
4023
4028
4030 {
4031 _state = ScanState.Error;
4032 return new XmlException(res, (string[])null);
4033 }
4034
4035 private Exception ThrowXmlException(string res, string arg1, string arg2)
4036 {
4037 _state = ScanState.Error;
4038 return new XmlException(res, new string[2] { arg1, arg2 });
4039 }
4040
4042 {
4043 _state = ScanState.Error;
4044 return new NotSupportedException(res);
4045 }
4046}
static unsafe void Clear(Array array)
Definition Array.cs:755
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static short ReadInt16LittleEndian(ReadOnlySpan< byte > source)
static ulong ReadUInt64LittleEndian(ReadOnlySpan< byte > source)
static ushort ReadUInt16LittleEndian(ReadOnlySpan< byte > source)
static uint ReadUInt32LittleEndian(ReadOnlySpan< byte > source)
static float ReadSingleLittleEndian(ReadOnlySpan< byte > source)
static double ReadDoubleLittleEndian(ReadOnlySpan< byte > source)
static bool TryReadUInt16LittleEndian(ReadOnlySpan< byte > source, out ushort value)
static int ReadInt32LittleEndian(ReadOnlySpan< byte > source)
static long ReadInt64LittleEndian(ReadOnlySpan< byte > source)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
void Add(TKey key, TValue value)
static string ToBase64String(byte[] inArray)
Definition Convert.cs:2675
static CultureInfo InvariantCulture
int Read(byte[] buffer, int offset, int count)
void Dispose()
Definition Stream.cs:639
static string XmlBin_InvalidQNameID
Definition SR.cs:1364
static string Xml_UnexpectedEOF1
Definition SR.cs:38
static string Xml_PrefixForEmptyNs
Definition SR.cs:286
static string SqlTypes_ArithOverflow
Definition SR.cs:1390
static string XmlBinary_UnsupportedCodePage
Definition SR.cs:1374
static string Xml_DtdNotAllowedInFragment
Definition SR.cs:164
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Xml_DtdIsProhibited
Definition SR.cs:158
static string Xml_BadDTDLocation
Definition SR.cs:98
static string Xml_ReadContentAsFormatException
Definition SR.cs:190
static string Xml_InvalidSurrogateMissingLowChar
Definition SR.cs:324
static string XmlBinary_InvalidStandalone
Definition SR.cs:1376
static string XmlBinary_NoRemapPrefix
Definition SR.cs:1384
static string Xml_BadNamespaceDecl
Definition SR.cs:134
static string Xml_InvalidRootData
Definition SR.cs:82
static string XmlBinary_ListsOfValuesNotSupported
Definition SR.cs:1380
static string XmlBinary_AttrWithNsNoPrefix
Definition SR.cs:1386
static string XmlBinary_InvalidSignature
Definition SR.cs:1370
static string XmlBinary_InvalidProtocolVersion
Definition SR.cs:1372
static string XmlBinary_CastNotSupported
Definition SR.cs:1382
static string Xml_DupAttributeName
Definition SR.cs:96
static string XmlBinary_ValueTooBig
Definition SR.cs:1388
static string XmlBin_MissingEndCDATA
Definition SR.cs:1362
static string Xml_UnexpectedEndTag
Definition SR.cs:70
static string XmlBinary_UnexpectedToken
Definition SR.cs:1366
Definition SR.cs:7
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
unsafe string GetString(byte *bytes, int byteCount)
Definition Encoding.cs:973
static void Encode(byte[] buffer, int index, int count, XmlWriter writer)
static DateTime XsdKatmaiDateOffsetToDateTime(byte[] data, int offset)
static string XsdKatmaiTimeToString(byte[] data, int offset)
static string XsdKatmaiDateToString(byte[] data, int offset)
static DateTimeOffset XsdKatmaiTimeOffsetToDateTimeOffset(byte[] data, int offset)
static string XsdKatmaiDateTimeOffsetToString(byte[] data, int offset)
static string SqlSmallDateTimeToString(short dateticks, ushort timeticks)
static string XsdKatmaiTimeOffsetToString(byte[] data, int offset)
static DateTime XsdKatmaiDateToDateTime(byte[] data, int offset)
static DateTime XsdKatmaiTimeOffsetToDateTime(byte[] data, int offset)
static DateTime XsdDateTimeToDateTime(long val)
static DateTime XsdKatmaiDateTimeOffsetToDateTime(byte[] data, int offset)
static string XsdDateToString(long val)
static DateTime XsdTimeToDateTime(long val)
static DateTime XsdKatmaiDateTimeToDateTime(byte[] data, int offset)
static string XsdKatmaiDateTimeToString(byte[] data, int offset)
static DateTime XsdDateToDateTime(long val)
static string SqlDateTimeToString(int dateticks, uint timeticks)
static string XsdDateTimeToString(long val)
static DateTime SqlDateTimeToDateTime(int dateticks, uint timeticks)
static DateTimeOffset XsdKatmaiDateTimeOffsetToDateTimeOffset(byte[] data, int offset)
static string XsdTimeToString(long val)
static DateTime SqlSmallDateTimeToDateTime(short dateticks, ushort timeticks)
static DateTime XsdKatmaiTimeToDateTime(byte[] data, int offset)
static DateTimeOffset XsdKatmaiDateOffsetToDateTimeOffset(byte[] data, int offset)
static string XsdKatmaiDateOffsetToString(byte[] data, int offset)
static bool Equal(string strA, string strB)
Definition Ref.cs:5
static XmlSchemaSimpleType GetSimpleTypeFromTypeCode(XmlTypeCode typeCode)
object ChangeType(bool value, Type destinationType)
static void SplitQName(string name, out string prefix, out string lname)
static bool IsWhiteSpace(char ch)
static bool IsLowSurrogate(int ch)
static bool IsCharData(char ch)
static bool IsHighSurrogate(int ch)
static bool ToBoolean(string s)
static void VerifyCharData(string data, ExceptionType exceptionType)
static int ToInt32(string s)
static string ToString(bool value)
static float ToSingle(string s)
static double ToDouble(string s)
static Exception CreateInvalidCharException(char[] data, int length, int invCharPos, ExceptionType exceptionType)
static Exception CreateInvalidSurrogatePairException(char low, char hi)
static DateTime ToDateTime(string s)
static decimal ToDecimal(string s)
static long ToInt64(string s)
string Add(char[] array, int offset, int length)
string? Get(char[] array, int offset, int length)
virtual XmlSpace XmlSpace
Definition XmlReader.cs:96
string? GetAttribute(string name)
virtual bool HasValue
Definition XmlReader.cs:82
bool MoveToAttribute(string name)
Exception CreateReadContentAsException(string methodName)
static bool HasValueInternal(XmlNodeType nodeType)
virtual string XmlLang
Definition XmlReader.cs:98
string? LookupNamespace(string prefix)
virtual void Close()
Definition XmlReader.cs:528
XmlNodeType NodeType
Definition XmlReader.cs:62
static bool CanReadContentAs(XmlNodeType nodeType)
NamespaceDecl(string prefix, string nsuri, NamespaceDecl nextInScope, NamespaceDecl prevDecl, int scope, bool implied)
NestedBinXml(SymbolTables symbolTables, int docState, NestedBinXml next)
XmlSqlBinaryReader(Stream stream, byte[] data, int len, string baseUri, bool closeInput, XmlReaderSettings settings)
void AddInitNamespace(string prefix, string uri)
object ValueAsObject(BinXmlToken token, bool returnInternalTypes)
override string LookupNamespace(string prefix)
Type GetValueType(BinXmlToken token)
XmlNodeType ScanOverValue(BinXmlToken token, bool attr, bool checkChars)
int LocateAttribute(string name, string ns)
string GetString(int pos, int cch)
static readonly ReadState[] s_scanState2ReadState
override string GetAttribute(string name)
override void MoveToAttribute(int i)
override string GetAttribute(int i)
override string GetAttribute(string name, string ns)
object ValueAs(BinXmlToken token, Type returnType, IXmlNamespaceResolver namespaceResolver)
BinXmlToken NextToken2(BinXmlToken token)
static ReadOnlySpan< byte > XsdKatmaiTimeScaleToValueLengthMap
override bool MoveToAttribute(string name)
override bool MoveToAttribute(string name, string ns)
Exception ThrowXmlException(string res)
readonly DtdProcessing _dtdProcessing
string ValueAsString(BinXmlToken token)
int XsdKatmaiTimeScaleToValueLength(byte scale)
Exception ThrowXmlException(string res, string arg1, string arg2)
void ImplReadData(BinXmlToken tokenType)
void PopNamespaces(NamespaceDecl firstInScopeChain)
int GetXsdKatmaiTokenLength(BinXmlToken token)
override DateTime ReadContentAsDateTime()
void ReScanOverValue(BinXmlToken token)
XmlNodeType ScanOverAnyValue(BinXmlToken token, bool attr, bool checkChars)
void VerifyVersion(int requiredVersion, BinXmlToken token)
bool UpdateFromTextReader(bool needUpdate)
override XmlReaderSettings Settings
readonly Dictionary< string, NamespaceDecl > _namespaces
Exception ThrowUnexpectedToken(BinXmlToken token)
static volatile Type[] s_tokenTypeMap
Exception ThrowNotSupported(string res)
override object ReadContentAs(Type returnType, IXmlNamespaceResolver namespaceResolver)
void PushNamespace(string prefix, string ns, bool implied)
XmlValueConverter GetValueConverter(XmlTypeCode typeCode)
IDictionary< string, string > GetNamespacesInScope(XmlNamespaceScope scope)
string? LookupPrefix(string namespaceName)
override string ToString()
bool MatchHashNS(int hash, string localname, string namespaceUri)
bool MatchNS(string localname, string namespaceUri)
int GetLocalnameAndNamespaceUriAndHash(out string localname, out string namespaceUri)
void GetLocalnameAndNamespaceUri(out string localname, out string namespaceUri)
void Set(QName name, bool xmlspacePreserve)
static bool operator!=(QName a, QName b)
void CheckPrefixNS(string prefix, string namespaceUri)
QName(string prefix, string lname, string nsUri)
bool MatchPrefix(string prefix, string lname)
static bool operator==(QName a, QName b)
void Set(string prefix, string lname, string nsUri)
override bool Equals([NotNullWhen(true)] object other)
bool MatchNs(string lname, string nsUri)