1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
4 using System.Collections.Generic;
5 using System.Diagnostics.CodeAnalysis;
6 using System.Globalization;
7 using System.Runtime.Serialization.DataContracts;
9 using System.Xml.Serialization;
11 namespace System.Runtime.Serialization
13 internal class XmlReaderDelegator
15 protected XmlReader reader;
16 protected XmlDictionaryReader? dictionaryReader;
17 protected bool isEndOfEmptyElement;
19 public XmlReaderDelegator(XmlReader reader)
21 ArgumentNullException.ThrowIfNull(reader);
24 this.dictionaryReader = reader as XmlDictionaryReader;
27 internal XmlReader UnderlyingReader
29 get { return reader; }
32 internal ExtensionDataReader? UnderlyingExtensionDataReader
34 get { return reader as ExtensionDataReader; }
37 internal int AttributeCount
39 get { return isEndOfEmptyElement ? 0 : reader.AttributeCount; }
42 internal string? GetAttribute(string name)
44 return isEndOfEmptyElement ? null : reader.GetAttribute(name);
47 internal string? GetAttribute(string name, string namespaceUri)
49 return isEndOfEmptyElement ? null : reader.GetAttribute(name, namespaceUri);
52 internal string GetAttribute(int i)
54 if (isEndOfEmptyElement)
55 throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(i), SR.XmlElementAttributes));
56 return reader.GetAttribute(i);
59 [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Conceptually, this property describes this instance. Callers should expect to have an instance on hand to 'ask' about this 'emtpy' circumstance.")]
60 internal bool IsEmptyElement
65 internal bool IsNamespaceURI(string ns)
67 if (dictionaryReader == null)
68 return ns == reader.NamespaceURI;
70 return dictionaryReader.IsNamespaceUri(ns);
73 internal bool IsLocalName(string localName)
75 if (dictionaryReader == null)
76 return localName == reader.LocalName;
78 return dictionaryReader.IsLocalName(localName);
81 internal bool IsNamespaceUri(XmlDictionaryString ns)
83 if (dictionaryReader == null)
84 return ns.Value == reader.NamespaceURI;
86 return dictionaryReader.IsNamespaceUri(ns);
89 internal bool IsLocalName(XmlDictionaryString localName)
91 if (dictionaryReader == null)
92 return localName.Value == reader.LocalName;
94 return dictionaryReader.IsLocalName(localName);
97 internal int IndexOfLocalName(XmlDictionaryString[] localNames, XmlDictionaryString ns)
99 if (dictionaryReader != null)
100 return dictionaryReader.IndexOfLocalName(localNames, ns);
102 if (reader.NamespaceURI == ns.Value)
104 string localName = this.LocalName;
105 for (int i = 0; i < localNames.Length; i++)
107 if (localName == localNames[i].Value)
117 internal bool IsStartElement()
119 return !isEndOfEmptyElement && reader.IsStartElement();
122 internal bool IsStartElement(string localname, string ns)
124 return !isEndOfEmptyElement && reader.IsStartElement(localname, ns);
127 internal bool IsStartElement(XmlDictionaryString localname, XmlDictionaryString ns)
129 if (dictionaryReader == null)
130 return !isEndOfEmptyElement && reader.IsStartElement(localname.Value, ns.Value);
132 return !isEndOfEmptyElement && dictionaryReader.IsStartElement(localname, ns);
135 internal bool MoveToAttribute(string name)
137 return isEndOfEmptyElement ? false : reader.MoveToAttribute(name);
140 internal bool MoveToAttribute(string name, string ns)
142 return isEndOfEmptyElement ? false : reader.MoveToAttribute(name, ns);
145 internal void MoveToAttribute(int i)
147 if (isEndOfEmptyElement)
148 throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(i), SR.XmlElementAttributes));
149 reader.MoveToAttribute(i);
152 internal bool MoveToElement()
154 return isEndOfEmptyElement ? false : reader.MoveToElement();
157 internal bool MoveToFirstAttribute()
159 return isEndOfEmptyElement ? false : reader.MoveToFirstAttribute();
162 internal bool MoveToNextAttribute()
164 return isEndOfEmptyElement ? false : reader.MoveToNextAttribute();
167 internal XmlNodeType NodeType
169 get { return isEndOfEmptyElement ? XmlNodeType.EndElement : reader.NodeType; }
174 //reader.MoveToFirstAttribute();
175 //if (NodeType == XmlNodeType.Attribute)
176 reader.MoveToElement();
177 if (!reader.IsEmptyElement)
178 return reader.Read();
179 if (isEndOfEmptyElement)
181 isEndOfEmptyElement = false;
182 return reader.Read();
184 isEndOfEmptyElement = true;
188 internal XmlNodeType MoveToContent()
190 if (isEndOfEmptyElement)
191 return XmlNodeType.EndElement;
193 return reader.MoveToContent();
196 internal bool ReadAttributeValue()
198 return isEndOfEmptyElement ? false : reader.ReadAttributeValue();
201 internal void ReadEndElement()
203 if (isEndOfEmptyElement)
206 reader.ReadEndElement();
209 private static InvalidDataContractException CreateInvalidPrimitiveTypeException(Type type)
211 return new InvalidDataContractException(SR.Format(
212 type.IsInterface ? SR.InterfaceTypeCannotBeCreated : SR.InvalidPrimitiveType_Serialization,
213 DataContract.GetClrTypeFullName(type)));
216 public object ReadElementContentAsAnyType(Type valueType)
219 object o = ReadContentAsAnyType(valueType);
224 internal object ReadContentAsAnyType(Type valueType)
226 switch (Type.GetTypeCode(valueType))
228 case TypeCode.Boolean:
229 return ReadContentAsBoolean();
231 return ReadContentAsChar();
233 return ReadContentAsUnsignedByte();
235 return ReadContentAsShort();
237 return ReadContentAsInt();
239 return ReadContentAsLong();
240 case TypeCode.Single:
241 return ReadContentAsSingle();
242 case TypeCode.Double:
243 return ReadContentAsDouble();
244 case TypeCode.Decimal:
245 return ReadContentAsDecimal();
246 case TypeCode.DateTime:
247 return ReadContentAsDateTime();
248 case TypeCode.String:
249 return ReadContentAsString();
252 return ReadContentAsSignedByte();
253 case TypeCode.UInt16:
254 return ReadContentAsUnsignedShort();
255 case TypeCode.UInt32:
256 return ReadContentAsUnsignedInt();
257 case TypeCode.UInt64:
258 return ReadContentAsUnsignedLong();
260 case TypeCode.DBNull:
261 case TypeCode.Object:
263 if (valueType == Globals.TypeOfByteArray)
264 return ReadContentAsBase64();
265 else if (valueType == Globals.TypeOfObject)
267 else if (valueType == Globals.TypeOfTimeSpan)
268 return ReadContentAsTimeSpan();
269 else if (valueType == Globals.TypeOfGuid)
270 return ReadContentAsGuid();
271 else if (valueType == Globals.TypeOfUri)
272 return ReadContentAsUri();
273 else if (valueType == Globals.TypeOfXmlQualifiedName)
274 return ReadContentAsQName();
277 throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
280 internal IDataNode ReadExtensionData(Type valueType)
282 switch (Type.GetTypeCode(valueType))
284 case TypeCode.Boolean:
285 return new DataNode<bool>(ReadContentAsBoolean());
287 return new DataNode<char>(ReadContentAsChar());
289 return new DataNode<byte>(ReadContentAsUnsignedByte());
291 return new DataNode<short>(ReadContentAsShort());
293 return new DataNode<int>(ReadContentAsInt());
295 return new DataNode<long>(ReadContentAsLong());
296 case TypeCode.Single:
297 return new DataNode<float>(ReadContentAsSingle());
298 case TypeCode.Double:
299 return new DataNode<double>(ReadContentAsDouble());
300 case TypeCode.Decimal:
301 return new DataNode<decimal>(ReadContentAsDecimal());
302 case TypeCode.DateTime:
303 return new DataNode<DateTime>(ReadContentAsDateTime());
304 case TypeCode.String:
305 return new DataNode<string>(ReadContentAsString());
307 return new DataNode<sbyte>(ReadContentAsSignedByte());
308 case TypeCode.UInt16:
309 return new DataNode<ushort>(ReadContentAsUnsignedShort());
310 case TypeCode.UInt32:
311 return new DataNode<uint>(ReadContentAsUnsignedInt());
312 case TypeCode.UInt64:
313 return new DataNode<ulong>(ReadContentAsUnsignedLong());
315 case TypeCode.DBNull:
316 case TypeCode.Object:
318 if (valueType == Globals.TypeOfByteArray)
319 return new DataNode<byte[]>(ReadContentAsBase64());
320 else if (valueType == Globals.TypeOfObject)
321 return new DataNode<object>(new object());
322 else if (valueType == Globals.TypeOfTimeSpan)
323 return new DataNode<TimeSpan>(ReadContentAsTimeSpan());
324 else if (valueType == Globals.TypeOfGuid)
325 return new DataNode<Guid>(ReadContentAsGuid());
326 else if (valueType == Globals.TypeOfUri)
327 return new DataNode<Uri>(ReadContentAsUri());
328 else if (valueType == Globals.TypeOfXmlQualifiedName)
329 return new DataNode<XmlQualifiedName>(ReadContentAsQName());
332 throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
336 private void ThrowConversionException(string value, string type)
338 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(XmlObjectSerializer.TryAddLineInfo(this, SR.Format(SR.XmlInvalidConversion, value, type))));
342 private static void ThrowNotAtElement()
344 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.XmlStartElementExpected, "EndElement")));
347 internal virtual char ReadElementContentAsChar()
349 return ToChar(ReadElementContentAsInt());
352 internal virtual char ReadContentAsChar()
354 return ToChar(ReadContentAsInt());
357 private char ToChar(int value)
359 if (value < char.MinValue || value > char.MaxValue)
361 ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "Char");
366 internal string ReadElementContentAsString()
368 if (isEndOfEmptyElement)
371 return reader.ReadElementContentAsString();
374 internal string ReadContentAsString()
376 return isEndOfEmptyElement ? string.Empty : reader.ReadContentAsString();
379 internal bool ReadElementContentAsBoolean()
381 if (isEndOfEmptyElement)
384 return reader.ReadElementContentAsBoolean();
387 internal bool ReadContentAsBoolean()
389 if (isEndOfEmptyElement)
390 ThrowConversionException(string.Empty, "Boolean");
392 return reader.ReadContentAsBoolean();
395 internal float ReadElementContentAsFloat()
397 if (isEndOfEmptyElement)
400 return reader.ReadElementContentAsFloat();
403 internal float ReadContentAsSingle()
405 if (isEndOfEmptyElement)
406 ThrowConversionException(string.Empty, "Float");
408 return reader.ReadContentAsFloat();
411 internal double ReadElementContentAsDouble()
413 if (isEndOfEmptyElement)
416 return reader.ReadElementContentAsDouble();
419 internal double ReadContentAsDouble()
421 if (isEndOfEmptyElement)
422 ThrowConversionException(string.Empty, "Double");
424 return reader.ReadContentAsDouble();
427 internal decimal ReadElementContentAsDecimal()
429 if (isEndOfEmptyElement)
432 return reader.ReadElementContentAsDecimal();
435 internal decimal ReadContentAsDecimal()
437 if (isEndOfEmptyElement)
438 ThrowConversionException(string.Empty, "Decimal");
440 return reader.ReadContentAsDecimal();
443 internal virtual byte[] ReadElementContentAsBase64()
445 if (isEndOfEmptyElement)
448 if (dictionaryReader == null)
450 return ReadContentAsBase64(reader.ReadElementContentAsString());
454 return dictionaryReader.ReadElementContentAsBase64();
458 public virtual byte[] ReadContentAsBase64()
460 if (isEndOfEmptyElement)
461 return Array.Empty<byte>();
463 if (dictionaryReader == null)
465 return ReadContentAsBase64(reader.ReadContentAsString());
469 return dictionaryReader.ReadContentAsBase64();
473 [return: NotNullIfNotNull(nameof(str))]
474 internal static byte[]? ReadContentAsBase64(string? str)
480 return Array.Empty<byte>();
484 return Convert.FromBase64String(str);
486 catch (ArgumentException exception)
488 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception));
490 catch (FormatException exception)
492 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception));
496 internal virtual DateTime ReadElementContentAsDateTime()
498 if (isEndOfEmptyElement)
501 return reader.ReadElementContentAsDateTime();
504 internal virtual DateTime ReadContentAsDateTime()
506 if (isEndOfEmptyElement)
507 ThrowConversionException(string.Empty, "DateTime");
509 return reader.ReadContentAsDateTime();
512 internal int ReadElementContentAsInt()
514 if (isEndOfEmptyElement)
517 return reader.ReadElementContentAsInt();
520 internal int ReadContentAsInt()
522 if (isEndOfEmptyElement)
523 ThrowConversionException(string.Empty, "Int32");
525 return reader.ReadContentAsInt();
528 internal long ReadElementContentAsLong()
530 if (isEndOfEmptyElement)
533 return reader.ReadElementContentAsLong();
536 internal long ReadContentAsLong()
538 if (isEndOfEmptyElement)
539 ThrowConversionException(string.Empty, "Int64");
541 return reader.ReadContentAsLong();
544 internal short ReadElementContentAsShort()
546 return ToShort(ReadElementContentAsInt());
549 internal short ReadContentAsShort()
551 return ToShort(ReadContentAsInt());
554 private short ToShort(int value)
556 if (value < short.MinValue || value > short.MaxValue)
558 ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "Int16");
563 internal byte ReadElementContentAsUnsignedByte()
565 return ToByte(ReadElementContentAsInt());
568 internal byte ReadContentAsUnsignedByte()
570 return ToByte(ReadContentAsInt());
573 private byte ToByte(int value)
575 if (value < byte.MinValue || value > byte.MaxValue)
577 ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "Byte");
582 internal sbyte ReadElementContentAsSignedByte()
584 return ToSByte(ReadElementContentAsInt());
587 internal sbyte ReadContentAsSignedByte()
589 return ToSByte(ReadContentAsInt());
592 private sbyte ToSByte(int value)
594 if (value < sbyte.MinValue || value > sbyte.MaxValue)
596 ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "SByte");
601 internal uint ReadElementContentAsUnsignedInt()
603 return ToUInt32(ReadElementContentAsLong());
606 internal uint ReadContentAsUnsignedInt()
608 return ToUInt32(ReadContentAsLong());
611 private uint ToUInt32(long value)
613 if (value < uint.MinValue || value > uint.MaxValue)
615 ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "UInt32");
620 internal virtual ulong ReadElementContentAsUnsignedLong()
622 if (isEndOfEmptyElement)
625 string str = reader.ReadElementContentAsString();
627 if (str == null || str.Length == 0)
628 ThrowConversionException(string.Empty, "UInt64");
630 return XmlConverter.ToUInt64(str);
633 internal virtual ulong ReadContentAsUnsignedLong()
635 string str = reader.ReadContentAsString();
637 if (str == null || str.Length == 0)
638 ThrowConversionException(string.Empty, "UInt64");
640 return XmlConverter.ToUInt64(str);
643 internal ushort ReadElementContentAsUnsignedShort()
645 return ToUInt16(ReadElementContentAsInt());
648 internal ushort ReadContentAsUnsignedShort()
650 return ToUInt16(ReadContentAsInt());
653 private ushort ToUInt16(int value)
655 if (value < ushort.MinValue || value > ushort.MaxValue)
657 ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "UInt16");
659 return (ushort)value;
662 internal TimeSpan ReadElementContentAsTimeSpan()
664 if (isEndOfEmptyElement)
667 string str = reader.ReadElementContentAsString();
668 return XmlConverter.ToTimeSpan(str);
671 internal TimeSpan ReadContentAsTimeSpan()
673 string str = reader.ReadContentAsString();
674 return XmlConverter.ToTimeSpan(str);
677 internal Guid ReadElementContentAsGuid()
679 if (isEndOfEmptyElement)
682 string str = reader.ReadElementContentAsString();
685 return new Guid(str);
687 catch (ArgumentException exception)
689 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
691 catch (FormatException exception)
693 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
695 catch (OverflowException exception)
697 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
701 internal Guid ReadContentAsGuid()
703 string str = reader.ReadContentAsString();
706 return Guid.Parse(str);
708 catch (ArgumentException exception)
710 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
712 catch (FormatException exception)
714 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
716 catch (OverflowException exception)
718 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
722 internal Uri ReadElementContentAsUri()
724 if (isEndOfEmptyElement)
727 string str = ReadElementContentAsString();
730 return new Uri(str, UriKind.RelativeOrAbsolute);
732 catch (ArgumentException exception)
734 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
736 catch (FormatException exception)
738 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
742 internal Uri ReadContentAsUri()
744 string str = ReadContentAsString();
747 return new Uri(str, UriKind.RelativeOrAbsolute);
749 catch (ArgumentException exception)
751 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
753 catch (FormatException exception)
755 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
759 internal XmlQualifiedName ReadElementContentAsQName()
762 XmlQualifiedName obj = ReadContentAsQName();
767 internal virtual XmlQualifiedName ReadContentAsQName()
769 return ParseQualifiedName(ReadContentAsString());
772 private XmlQualifiedName ParseQualifiedName(string str)
776 if (str == null || str.Length == 0)
777 name = ns = string.Empty;
779 XmlObjectSerializerReadContext.ParseQualifiedName(str, this, out name, out ns, out _);
780 return new XmlQualifiedName(name, ns);
783 private static void CheckExpectedArrayLength(XmlObjectSerializerReadContext context, int arrayLength)
785 context.IncrementItemCount(arrayLength);
788 protected int GetArrayLengthQuota(XmlObjectSerializerReadContext context)
790 if (dictionaryReader?.Quotas == null)
791 return context.RemainingItemCount;
793 return Math.Min(context.RemainingItemCount, dictionaryReader.Quotas.MaxArrayLength);
796 private static void CheckActualArrayLength(int expectedLength, int actualLength, XmlDictionaryString itemName, XmlDictionaryString itemNamespace)
798 if (expectedLength != actualLength)
799 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayExceededSizeAttribute, expectedLength, itemName.Value, itemNamespace.Value)));
802 internal bool TryReadBooleanArray(XmlObjectSerializerReadContext context,
803 XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
804 int arrayLength, [NotNullWhen(true)] out bool[]? array)
806 if (dictionaryReader == null)
812 if (arrayLength != -1)
814 CheckExpectedArrayLength(context, arrayLength);
815 array = new bool[arrayLength];
816 int read, offset = 0;
817 while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
821 CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
825 array = BooleanArrayHelperWithDictionaryString.Instance.ReadArray(
826 dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
827 context.IncrementItemCount(array.Length);
832 internal virtual bool TryReadDateTimeArray(XmlObjectSerializerReadContext context,
833 XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
834 int arrayLength, [NotNullWhen(true)] out DateTime[]? array)
836 if (dictionaryReader == null)
842 if (arrayLength != -1)
844 CheckExpectedArrayLength(context, arrayLength);
845 array = new DateTime[arrayLength];
846 int read, offset = 0;
847 while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
851 CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
855 array = DateTimeArrayHelperWithDictionaryString.Instance.ReadArray(
856 dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
857 context.IncrementItemCount(array.Length);
862 internal bool TryReadDecimalArray(XmlObjectSerializerReadContext context,
863 XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
864 int arrayLength, [NotNullWhen(true)] out decimal[]? array)
866 if (dictionaryReader == null)
872 if (arrayLength != -1)
874 CheckExpectedArrayLength(context, arrayLength);
875 array = new decimal[arrayLength];
876 int read, offset = 0;
877 while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
881 CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
885 array = DecimalArrayHelperWithDictionaryString.Instance.ReadArray(
886 dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
887 context.IncrementItemCount(array.Length);
892 internal bool TryReadInt32Array(XmlObjectSerializerReadContext context,
893 XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
894 int arrayLength, [NotNullWhen(true)] out int[]? array)
896 if (dictionaryReader == null)
902 if (arrayLength != -1)
904 CheckExpectedArrayLength(context, arrayLength);
905 array = new int[arrayLength];
906 int read, offset = 0;
907 while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
911 CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
915 array = Int32ArrayHelperWithDictionaryString.Instance.ReadArray(
916 dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
917 context.IncrementItemCount(array.Length);
922 internal bool TryReadInt64Array(XmlObjectSerializerReadContext context,
923 XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
924 int arrayLength, [NotNullWhen(true)] out long[]? array)
926 if (dictionaryReader == null)
932 if (arrayLength != -1)
934 CheckExpectedArrayLength(context, arrayLength);
935 array = new long[arrayLength];
936 int read, offset = 0;
937 while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
941 CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
945 array = Int64ArrayHelperWithDictionaryString.Instance.ReadArray(
946 dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
947 context.IncrementItemCount(array.Length);
952 internal bool TryReadSingleArray(XmlObjectSerializerReadContext context,
953 XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
954 int arrayLength, [NotNullWhen(true)] out float[]? array)
956 if (dictionaryReader == null)
962 if (arrayLength != -1)
964 CheckExpectedArrayLength(context, arrayLength);
965 array = new float[arrayLength];
966 int read, offset = 0;
967 while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
971 CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
975 array = SingleArrayHelperWithDictionaryString.Instance.ReadArray(
976 dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
977 context.IncrementItemCount(array.Length);
982 internal bool TryReadDoubleArray(XmlObjectSerializerReadContext context,
983 XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
984 int arrayLength, [NotNullWhen(true)] out double[]? array)
986 if (dictionaryReader == null)
992 if (arrayLength != -1)
994 CheckExpectedArrayLength(context, arrayLength);
995 array = new double[arrayLength];
996 int read, offset = 0;
997 while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
1001 CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
1005 array = DoubleArrayHelperWithDictionaryString.Instance.ReadArray(
1006 dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
1007 context.IncrementItemCount(array.Length);
1012 internal IDictionary<string, string>? GetNamespacesInScope(XmlNamespaceScope scope)
1014 return (reader is IXmlNamespaceResolver) ? ((IXmlNamespaceResolver)reader).GetNamespacesInScope(scope) : null;
1017 // IXmlLineInfo members
1018 internal bool HasLineInfo()
1020 IXmlLineInfo? iXmlLineInfo = reader as IXmlLineInfo;
1021 return (iXmlLineInfo == null) ? false : iXmlLineInfo.HasLineInfo();
1024 internal int LineNumber
1028 IXmlLineInfo? iXmlLineInfo = reader as IXmlLineInfo;
1029 return (iXmlLineInfo == null) ? 0 : iXmlLineInfo.LineNumber;
1033 internal int LinePosition
1037 IXmlLineInfo? iXmlLineInfo = reader as IXmlLineInfo;
1038 return (iXmlLineInfo == null) ? 0 : iXmlLineInfo.LinePosition;
1042 // IXmlTextParser members
1043 internal bool Normalized
1047 if (reader is not XmlTextReader xmlTextReader)
1049 IXmlTextParser? xmlTextParser = reader as IXmlTextParser;
1050 return (xmlTextParser == null) ? false : xmlTextParser.Normalized;
1053 return xmlTextReader.Normalization;
1057 if (reader is not XmlTextReader xmlTextReader)
1059 if (reader is IXmlTextParser xmlTextParser)
1060 xmlTextParser.Normalized = value;
1063 xmlTextReader.Normalization = value;
1067 internal WhitespaceHandling WhitespaceHandling
1071 if (reader is not XmlTextReader xmlTextReader)
1073 IXmlTextParser? xmlTextParser = reader as IXmlTextParser;
1074 return (xmlTextParser == null) ? WhitespaceHandling.None : xmlTextParser.WhitespaceHandling;
1077 return xmlTextReader.WhitespaceHandling;
1081 if (reader is not XmlTextReader xmlTextReader)
1083 if (reader is IXmlTextParser xmlTextParser)
1084 xmlTextParser.WhitespaceHandling = value;
1087 xmlTextReader.WhitespaceHandling = value;
1091 // delegating properties and methods
1092 internal string Name { get { return reader.Name; } }
1093 internal string LocalName { get { return reader.LocalName; } }
1094 internal string NamespaceURI { get { return reader.NamespaceURI; } }
1095 internal string Value { get { return reader.Value; } }
1096 internal Type ValueType { get { return reader.ValueType; } }
1097 internal int Depth { get { return reader.Depth; } }
1098 internal string? LookupNamespace(string prefix) { return reader.LookupNamespace(prefix); }
1099 internal bool EOF { get { return reader.EOF; } }
1101 internal void Skip()
1104 isEndOfEmptyElement = false;