diff --git a/src/libraries/System.Private.CoreLib/src/System/LocalAppContextSwitches.Common.cs b/src/libraries/System.Private.CoreLib/src/System/LocalAppContextSwitches.Common.cs
index 074177172381d..a892b2162331d 100644
--- a/src/libraries/System.Private.CoreLib/src/System/LocalAppContextSwitches.Common.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/LocalAppContextSwitches.Common.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Runtime.CompilerServices;
namespace System
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/AsyncHelper.cs b/src/libraries/System.Private.Xml/src/System/Xml/AsyncHelper.cs
index 692b8e21243ff..a527a0c890fc0 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/AsyncHelper.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/AsyncHelper.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Threading.Tasks;
namespace System.Xml
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Base64Decoder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Base64Decoder.cs
index 580ff0eb36db8..8e2726eab4cb7 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Base64Decoder.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Base64Decoder.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.Diagnostics;
@@ -12,7 +13,7 @@ internal class Base64Decoder : IncrementalReadDecoder
//
// Fields
//
- private byte[] _buffer;
+ private byte[]? _buffer;
private int _startIndex;
private int _curIndex;
private int _endIndex;
@@ -70,7 +71,7 @@ internal override unsafe int Decode(char[] chars, int startPos, int len)
int bytesDecoded, charsDecoded;
fixed (char* pChars = &chars[startPos])
{
- fixed (byte* pBytes = &_buffer[_curIndex])
+ fixed (byte* pBytes = &_buffer![_curIndex])
{
Decode(pChars, pChars + len, pBytes, pBytes + (_endIndex - _curIndex), out charsDecoded, out bytesDecoded);
}
@@ -102,14 +103,16 @@ internal override unsafe int Decode(string str, int startPos, int len)
{
return 0;
}
+
int bytesDecoded, charsDecoded;
fixed (char* pChars = str)
{
- fixed (byte* pBytes = &_buffer[_curIndex])
+ fixed (byte* pBytes = &_buffer![_curIndex])
{
Decode(pChars + startPos, pChars + startPos + len, pBytes, pBytes + (_endIndex - _curIndex), out charsDecoded, out bytesDecoded);
}
}
+
_curIndex += bytesDecoded;
return charsDecoded;
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Base64Encoder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Base64Encoder.cs
index e0fd83a8e91ba..0fa43260cbc72 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Base64Encoder.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Base64Encoder.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Text;
using System.Diagnostics;
@@ -9,7 +10,7 @@ namespace System.Xml
{
internal abstract partial class Base64Encoder
{
- private byte[] _leftOverBytes;
+ private byte[]? _leftOverBytes;
private int _leftOverBytesCount;
private readonly char[] _charsLine;
@@ -48,7 +49,7 @@ internal void Encode(byte[] buffer, int index, int count)
int i = _leftOverBytesCount;
while (i < 3 && count > 0)
{
- _leftOverBytes[i++] = buffer[index++];
+ _leftOverBytes![i++] = buffer[index++];
count--;
}
@@ -60,7 +61,7 @@ internal void Encode(byte[] buffer, int index, int count)
}
// encode the left-over buffer and write out
- int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes, 0, 3, _charsLine, 0);
+ int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes!, 0, 3, _charsLine, 0);
WriteChars(_charsLine, 0, leftOverChars);
}
@@ -99,7 +100,7 @@ internal void Flush()
{
if (_leftOverBytesCount > 0)
{
- int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes, 0, _leftOverBytesCount, _charsLine, 0);
+ int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes!, 0, _leftOverBytesCount, _charsLine, 0);
WriteChars(_charsLine, 0, leftOverChars);
_leftOverBytesCount = 0;
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Base64EncoderAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/Base64EncoderAsync.cs
index 56ba57825f61b..2930e5967cfcf 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Base64EncoderAsync.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Base64EncoderAsync.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Text;
using System.Diagnostics;
@@ -38,7 +39,7 @@ internal async Task EncodeAsync(byte[] buffer, int index, int count)
int i = _leftOverBytesCount;
while (i < 3 && count > 0)
{
- _leftOverBytes[i++] = buffer[index++];
+ _leftOverBytes![i++] = buffer[index++];
count--;
}
@@ -50,7 +51,7 @@ internal async Task EncodeAsync(byte[] buffer, int index, int count)
}
// encode the left-over buffer and write out
- int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes, 0, 3, _charsLine, 0);
+ int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes!, 0, 3, _charsLine, 0);
await WriteCharsAsync(_charsLine, 0, leftOverChars).ConfigureAwait(false);
}
@@ -89,7 +90,7 @@ internal async Task FlushAsync()
{
if (_leftOverBytesCount > 0)
{
- int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes, 0, _leftOverBytesCount, _charsLine, 0);
+ int leftOverChars = Convert.ToBase64CharArray(_leftOverBytes!, 0, _leftOverBytesCount, _charsLine, 0);
await WriteCharsAsync(_charsLine, 0, leftOverChars).ConfigureAwait(false);
_leftOverBytesCount = 0;
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/BinHexDecoder.cs b/src/libraries/System.Private.Xml/src/System/Xml/BinHexDecoder.cs
index 169c7fad63288..bed87b0403b81 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/BinHexDecoder.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/BinHexDecoder.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.Diagnostics;
@@ -12,7 +13,7 @@ internal class BinHexDecoder : IncrementalReadDecoder
//
// Fields
//
- private byte[] _buffer;
+ private byte[]? _buffer;
private int _startIndex;
private int _curIndex;
private int _endIndex;
@@ -61,10 +62,11 @@ internal override unsafe int Decode(char[] chars, int startPos, int len)
{
return 0;
}
+
int bytesDecoded, charsDecoded;
fixed (char* pChars = &chars[startPos])
{
- fixed (byte* pBytes = &_buffer[_curIndex])
+ fixed (byte* pBytes = &_buffer![_curIndex])
{
Decode(pChars, pChars + len, pBytes, pBytes + (_endIndex - _curIndex),
ref _hasHalfByteCached, ref _cachedHalfByte, out charsDecoded, out bytesDecoded);
@@ -97,15 +99,17 @@ internal override unsafe int Decode(string str, int startPos, int len)
{
return 0;
}
+
int bytesDecoded, charsDecoded;
fixed (char* pChars = str)
{
- fixed (byte* pBytes = &_buffer[_curIndex])
+ fixed (byte* pBytes = &_buffer![_curIndex])
{
Decode(pChars + startPos, pChars + startPos + len, pBytes, pBytes + (_endIndex - _curIndex),
ref _hasHalfByteCached, ref _cachedHalfByte, out charsDecoded, out bytesDecoded);
}
}
+
_curIndex += bytesDecoded;
return charsDecoded;
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/BinHexEncoder.cs b/src/libraries/System.Private.Xml/src/System/Xml/BinHexEncoder.cs
index 45125839c4c0e..1aba445ea8999 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/BinHexEncoder.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/BinHexEncoder.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Xml
{
internal static partial class BinHexEncoder
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/BinHexEncoderAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/BinHexEncoderAsync.cs
index 241db76570548..26b4cb5604833 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/BinHexEncoderAsync.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/BinHexEncoderAsync.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Threading.Tasks;
namespace System.Xml
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/BitStack.cs b/src/libraries/System.Private.Xml/src/System/Xml/BitStack.cs
index 8330fcbdabf34..030cddaee5f3b 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/BitStack.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/BitStack.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.Diagnostics;
@@ -12,7 +13,7 @@ namespace System.Xml
///
internal class BitStack
{
- private uint[] _bitStack;
+ private uint[]? _bitStack;
private int _stackPos;
private uint _curr;
@@ -108,7 +109,7 @@ private void PushCurr()
private void PopCurr()
{
if (_stackPos > 0)
- _curr = _bitStack[--_stackPos];
+ _curr = _bitStack![--_stackPos];
}
}
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Bits.cs b/src/libraries/System.Private.Xml/src/System/Xml/Bits.cs
index a2c4738d94764..6cbbb30c394f2 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Bits.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Bits.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.Diagnostics;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/ByteStack.cs b/src/libraries/System.Private.Xml/src/System/Xml/ByteStack.cs
index 7c7b9a07755fd..68fef684b0327 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/ByteStack.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/ByteStack.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
namespace System.Xml
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/Shape.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/Shape.cs
index f92e75c749c55..87de0f705c48d 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/Shape.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/Shape.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/ShapeGenerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/ShapeGenerator.cs
index 78b2f4c14f7c0..751083c35274d 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/ShapeGenerator.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/ShapeGenerator.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentView.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentView.cs
index f0499ce113bcc..786ac87474c88 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentView.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentView.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeView.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeView.cs
index 5eff6e34c1e7d..6003f56c91072 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeView.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeView.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeViewPropertyDescriptor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeViewPropertyDescriptor.cs
index 22c7a92d48334..e0e2ec847b513 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeViewPropertyDescriptor.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeViewPropertyDescriptor.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
#if ENABLEDATABINDING
using System;
using System.Xml;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/IDtdInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/IDtdInfo.cs
index 2eb890599e6fa..81c2264c9a946 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/IDtdInfo.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/IDtdInfo.cs
@@ -216,15 +216,15 @@ internal interface IDtdEntityInfo
///
/// SYSTEM identifier (URI) of the entity value - only used for external entities
///
- string SystemId { get; }
+ string? SystemId { get; }
///
/// PUBLIC identifier of the entity value - only used for external entities
///
- string PublicId { get; }
+ string? PublicId { get; }
///
/// Replacement text of an entity. Valid only for internal entities.
///
- string Text { get; }
+ string? Text { get; }
///
/// The line number of the entity value
///
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/IDtdParserAdapter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/IDtdParserAdapter.cs
index 0d9075f35f9e1..1ecfd3c7857b8 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/IDtdParserAdapter.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/IDtdParserAdapter.cs
@@ -4,6 +4,7 @@
#nullable enable
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Xml.Schema;
@@ -16,7 +17,7 @@ internal partial interface IDtdParserAdapter
Uri? BaseUri { get; }
- char[]? ParsingBuffer { get; }
+ char[] ParsingBuffer { get; }
int ParsingBufferLength { get; }
int CurrentPosition { get; set; }
int LineNo { get; }
@@ -29,21 +30,22 @@ internal partial interface IDtdParserAdapter
void OnNewLine(int pos);
- int ParseNumericCharRef(StringBuilder internalSubsetBuilder);
- int ParseNamedCharRef(bool expand, StringBuilder internalSubsetBuilder);
- void ParsePI(StringBuilder sb);
- void ParseComment(StringBuilder sb);
+ int ParseNumericCharRef(StringBuilder? internalSubsetBuilder);
+ int ParseNamedCharRef(bool expand, StringBuilder? internalSubsetBuilder);
+ void ParsePI(StringBuilder? sb);
+ void ParseComment(StringBuilder? sb);
bool PushEntity(IDtdEntityInfo entity, out int entityId);
bool PopEntity(out IDtdEntityInfo? oldEntity, out int newEntityId);
- bool PushExternalSubset(string systemId, string publicId);
+ bool PushExternalSubset(string? systemId, string? publicId);
void PushInternalDtd(string baseUri, string internalDtd);
void OnSystemId(string systemId, LineInfo keywordLineInfo, LineInfo systemLiteralLineInfo);
void OnPublicId(string publicId, LineInfo keywordLineInfo, LineInfo publicLiteralLineInfo);
+ [DoesNotReturn]
void Throw(Exception e);
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadContentAsBinaryHelper.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadContentAsBinaryHelper.cs
index cba84e3601283..7f88a6680f420 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadContentAsBinaryHelper.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadContentAsBinaryHelper.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Diagnostics;
namespace System.Xml
@@ -23,12 +24,12 @@ private enum State
private bool _isEnd;
private readonly bool _canReadValueChunk;
- private readonly char[] _valueChunk;
+ private readonly char[]? _valueChunk;
private int _valueChunkLength;
- private IncrementalReadDecoder _decoder;
- private Base64Decoder _base64Decoder;
- private BinHexDecoder _binHexDecoder;
+ private IncrementalReadDecoder? _decoder;
+ private Base64Decoder? _base64Decoder;
+ private BinHexDecoder? _binHexDecoder;
// Constants
private const int ChunkSize = 256;
@@ -46,7 +47,7 @@ internal ReadContentAsBinaryHelper(XmlReader reader)
}
// Static methods
- internal static ReadContentAsBinaryHelper CreateOrReset(ReadContentAsBinaryHelper helper, XmlReader reader)
+ internal static ReadContentAsBinaryHelper CreateOrReset(ReadContentAsBinaryHelper? helper, XmlReader reader)
{
if (helper == null)
{
@@ -398,7 +399,7 @@ private int ReadContentAsBinary(byte[] buffer, int index, int count)
{
if (_valueOffset < _valueChunkLength)
{
- int decodedCharsCount = _decoder.Decode(_valueChunk, _valueOffset, _valueChunkLength - _valueOffset);
+ int decodedCharsCount = _decoder.Decode(_valueChunk!, _valueOffset, _valueChunkLength - _valueOffset);
_valueOffset += decodedCharsCount;
}
if (_decoder.IsFull)
@@ -406,7 +407,7 @@ private int ReadContentAsBinary(byte[] buffer, int index, int count)
return _decoder.DecodedCount;
}
Debug.Assert(_valueOffset == _valueChunkLength);
- if ((_valueChunkLength = _reader.ReadValueChunk(_valueChunk, 0, ChunkSize)) == 0)
+ if ((_valueChunkLength = _reader.ReadValueChunk(_valueChunk!, 0, ChunkSize)) == 0)
{
break;
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadOnlyTernaryTree.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadOnlyTernaryTree.cs
index 1d0230dedc26e..3b20dc4e51f77 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadOnlyTernaryTree.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadOnlyTernaryTree.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.IO;
using System.Diagnostics;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlCharCheckingReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlCharCheckingReader.cs
index 87fad1990f408..73b7910d4b744 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlCharCheckingReader.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlCharCheckingReader.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.Xml;
using System.Diagnostics;
@@ -42,7 +43,7 @@ private enum State
private XmlNodeType _lastNodeType;
private XmlCharType _xmlCharType;
- private ReadContentAsBinaryHelper _readBinaryHelper;
+ private ReadContentAsBinaryHelper? _readBinaryHelper;
//
// Constructor
@@ -75,7 +76,7 @@ public override XmlReaderSettings Settings
{
get
{
- XmlReaderSettings settings = reader.Settings;
+ XmlReaderSettings? settings = reader.Settings;
if (settings == null)
{
settings = new XmlReaderSettings();
@@ -310,7 +311,7 @@ public override bool Read()
ValidateQName(base.reader.Name);
CheckCharacters(base.reader.Value);
- string str;
+ string? str;
str = base.reader.GetAttribute("SYSTEM");
if (str != null)
{
@@ -611,13 +612,13 @@ public override int ReadElementContentAsBinHex(byte[] buffer, int index, int cou
private void Throw(string res, string arg)
{
_state = State.Error;
- throw new XmlException(res, arg, (IXmlLineInfo)null);
+ throw new XmlException(res, arg, (IXmlLineInfo?)null);
}
private void Throw(string res, string[] args)
{
_state = State.Error;
- throw new XmlException(res, args, (IXmlLineInfo)null);
+ throw new XmlException(res, args, (IXmlLineInfo?)null);
}
private void CheckWhitespace(string value)
@@ -688,12 +689,12 @@ IDictionary IXmlNamespaceResolver.GetNamespacesInScope(XmlNamesp
return readerAsNSResolver.GetNamespacesInScope(scope);
}
- string IXmlNamespaceResolver.LookupNamespace(string prefix)
+ string? IXmlNamespaceResolver.LookupNamespace(string prefix)
{
return readerAsNSResolver.LookupNamespace(prefix);
}
- string IXmlNamespaceResolver.LookupPrefix(string namespaceName)
+ string? IXmlNamespaceResolver.LookupPrefix(string namespaceName)
{
return readerAsNSResolver.LookupPrefix(namespaceName);
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEventCache.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEventCache.cs
index b036585efbb22..3dfee72f30463 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEventCache.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEventCache.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
@@ -15,8 +16,8 @@ namespace System.Xml
///
internal sealed class XmlEventCache : XmlRawWriter
{
- private List _pages; // All event pages
- private XmlEvent[] _pageCurr; // Page that is currently being built
+ private List? _pages; // All event pages
+ private XmlEvent[]? _pageCurr; // Page that is currently being built
private int _pageSize; // Number of events in pageCurr
private readonly bool _hasRootNode; // True if the cached document has a root node, false if it's a fragment
private StringConcat _singleText; // If document consists of a single text node, cache it here rather than creating pages
@@ -100,7 +101,7 @@ public void EventsToWriter(XmlWriter writer)
int idxPage, idxEvent;
byte[] bytes;
char[] chars;
- XmlRawWriter rawWriter;
+ XmlRawWriter? rawWriter;
// Special-case single text node at the top-level
if (_singleText.Count != 0)
@@ -112,7 +113,7 @@ public void EventsToWriter(XmlWriter writer)
rawWriter = writer as XmlRawWriter;
// Loop over set of pages
- for (idxPage = 0; idxPage < _pages.Count; idxPage++)
+ for (idxPage = 0; idxPage < _pages!.Count; idxPage++)
{
page = _pages[idxPage];
@@ -127,15 +128,15 @@ public void EventsToWriter(XmlWriter writer)
return;
case XmlEventType.DocType:
- writer.WriteDocType(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3, (string)page[idxEvent].Object);
+ writer.WriteDocType(page[idxEvent].String1!, page[idxEvent].String2, page[idxEvent].String3, (string?)page[idxEvent].Object);
break;
case XmlEventType.StartElem:
- writer.WriteStartElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
+ writer.WriteStartElement(page[idxEvent].String1, page[idxEvent].String2!, page[idxEvent].String3);
break;
case XmlEventType.StartAttr:
- writer.WriteStartAttribute(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
+ writer.WriteStartAttribute(page[idxEvent].String1, page[idxEvent].String2!, page[idxEvent].String3);
break;
case XmlEventType.EndAttr:
@@ -147,15 +148,15 @@ public void EventsToWriter(XmlWriter writer)
break;
case XmlEventType.Comment:
- writer.WriteComment(page[idxEvent].String1);
+ writer.WriteComment(page[idxEvent].String1!);
break;
case XmlEventType.PI:
- writer.WriteProcessingInstruction(page[idxEvent].String1, page[idxEvent].String2);
+ writer.WriteProcessingInstruction(page[idxEvent].String1!, page[idxEvent].String2!);
break;
case XmlEventType.Whitespace:
- writer.WriteWhitespace(page[idxEvent].String1);
+ writer.WriteWhitespace(page[idxEvent].String1!);
break;
case XmlEventType.String:
@@ -163,40 +164,40 @@ public void EventsToWriter(XmlWriter writer)
break;
case XmlEventType.Raw:
- writer.WriteRaw(page[idxEvent].String1);
+ writer.WriteRaw(page[idxEvent].String1!);
break;
case XmlEventType.EntRef:
- writer.WriteEntityRef(page[idxEvent].String1);
+ writer.WriteEntityRef(page[idxEvent].String1!);
break;
case XmlEventType.CharEnt:
- writer.WriteCharEntity((char)page[idxEvent].Object);
+ writer.WriteCharEntity((char)page[idxEvent].Object!);
break;
case XmlEventType.SurrCharEnt:
- chars = (char[])page[idxEvent].Object;
+ chars = (char[])page[idxEvent].Object!;
writer.WriteSurrogateCharEntity(chars[0], chars[1]);
break;
case XmlEventType.Base64:
- bytes = (byte[])page[idxEvent].Object;
+ bytes = (byte[])page[idxEvent].Object!;
writer.WriteBase64(bytes, 0, bytes.Length);
break;
case XmlEventType.BinHex:
- bytes = (byte[])page[idxEvent].Object;
+ bytes = (byte[])page[idxEvent].Object!;
writer.WriteBinHex(bytes, 0, bytes.Length);
break;
case XmlEventType.XmlDecl1:
if (rawWriter != null)
- rawWriter.WriteXmlDeclaration((XmlStandalone)page[idxEvent].Object);
+ rawWriter.WriteXmlDeclaration((XmlStandalone)page[idxEvent].Object!);
break;
case XmlEventType.XmlDecl2:
if (rawWriter != null)
- rawWriter.WriteXmlDeclaration(page[idxEvent].String1);
+ rawWriter.WriteXmlDeclaration(page[idxEvent].String1!);
break;
case XmlEventType.StartContent:
@@ -206,23 +207,23 @@ public void EventsToWriter(XmlWriter writer)
case XmlEventType.EndElem:
if (rawWriter != null)
- rawWriter.WriteEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
+ rawWriter.WriteEndElement(page[idxEvent].String1!, page[idxEvent].String2!, page[idxEvent].String3!);
else
writer.WriteEndElement();
break;
case XmlEventType.FullEndElem:
if (rawWriter != null)
- rawWriter.WriteFullEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
+ rawWriter.WriteFullEndElement(page[idxEvent].String1!, page[idxEvent].String2!, page[idxEvent].String3!);
else
writer.WriteFullEndElement();
break;
case XmlEventType.Nmsp:
if (rawWriter != null)
- rawWriter.WriteNamespaceDeclaration(page[idxEvent].String1, page[idxEvent].String2);
+ rawWriter.WriteNamespaceDeclaration(page[idxEvent].String1!, page[idxEvent].String2!);
else
- writer.WriteAttributeString("xmlns", page[idxEvent].String1, XmlReservedNs.NsXmlNs, page[idxEvent].String2);
+ writer.WriteAttributeString("xmlns", page[idxEvent].String1!, XmlReservedNs.NsXmlNs, page[idxEvent].String2!);
break;
case XmlEventType.EndBase64:
@@ -270,7 +271,7 @@ public string EventsToString()
// Loop over set of pages
inAttr = false;
- for (idxPage = 0; idxPage < _pages.Count; idxPage++)
+ for (idxPage = 0; idxPage < _pages!.Count; idxPage++)
{
page = _pages[idxPage];
@@ -315,22 +316,22 @@ public string EventsToString()
// XmlWriter interface
//-----------------------------------------------
- public override XmlWriterSettings Settings
+ public override XmlWriterSettings? Settings
{
get { return null; }
}
- public override void WriteDocType(string name, string pubid, string sysid, string subset)
+ public override void WriteDocType(string name, string? pubid, string? sysid, string? subset)
{
AddEvent(XmlEventType.DocType, name, pubid, sysid, subset);
}
- public override void WriteStartElement(string prefix, string localName, string ns)
+ public override void WriteStartElement(string? prefix, string localName, string? ns)
{
AddEvent(XmlEventType.StartElem, prefix, localName, ns);
}
- public override void WriteStartAttribute(string prefix, string localName, string ns)
+ public override void WriteStartAttribute(string? prefix, string localName, string? ns)
{
AddEvent(XmlEventType.StartAttr, prefix, localName, ns);
}
@@ -340,7 +341,7 @@ public override void WriteEndAttribute()
AddEvent(XmlEventType.EndAttr);
}
- public override void WriteCData(string text)
+ public override void WriteCData(string? text)
{
AddEvent(XmlEventType.CData, text);
}
@@ -360,7 +361,7 @@ public override void WriteWhitespace(string ws)
AddEvent(XmlEventType.Whitespace, ws);
}
- public override void WriteString(string text)
+ public override void WriteString(string? text)
{
// Special-case single text node at the top level
if (_pages == null)
@@ -429,12 +430,12 @@ public override void Flush()
/// All other WriteValue methods are implemented by XmlWriter to delegate to WriteValue(object) or WriteValue(string), so
/// only these two methods need to be implemented.
///
- public override void WriteValue(object value)
+ public override void WriteValue(object? value)
{
WriteString(XmlUntypedConverter.Untyped.ToString(value, this.resolver));
}
- public override void WriteValue(string value)
+ public override void WriteValue(string? value)
{
WriteString(value);
}
@@ -502,37 +503,37 @@ internal override void WriteEndBase64()
private void AddEvent(XmlEventType eventType)
{
int idx = NewEvent();
- _pageCurr[idx].InitEvent(eventType);
+ _pageCurr![idx].InitEvent(eventType);
}
- private void AddEvent(XmlEventType eventType, string s1)
+ private void AddEvent(XmlEventType eventType, string? s1)
{
int idx = NewEvent();
- _pageCurr[idx].InitEvent(eventType, s1);
+ _pageCurr![idx].InitEvent(eventType, s1);
}
- private void AddEvent(XmlEventType eventType, string s1, string s2)
+ private void AddEvent(XmlEventType eventType, string? s1, string? s2)
{
int idx = NewEvent();
- _pageCurr[idx].InitEvent(eventType, s1, s2);
+ _pageCurr![idx].InitEvent(eventType, s1, s2);
}
- private void AddEvent(XmlEventType eventType, string s1, string s2, string s3)
+ private void AddEvent(XmlEventType eventType, string? s1, string? s2, string? s3)
{
int idx = NewEvent();
- _pageCurr[idx].InitEvent(eventType, s1, s2, s3);
+ _pageCurr![idx].InitEvent(eventType, s1, s2, s3);
}
- private void AddEvent(XmlEventType eventType, string s1, string s2, string s3, object o)
+ private void AddEvent(XmlEventType eventType, string? s1, string? s2, string? s3, object? o)
{
int idx = NewEvent();
- _pageCurr[idx].InitEvent(eventType, s1, s2, s3, o);
+ _pageCurr![idx].InitEvent(eventType, s1, s2, s3, o);
}
- private void AddEvent(XmlEventType eventType, object o)
+ private void AddEvent(XmlEventType eventType, object? o)
{
int idx = NewEvent();
- _pageCurr[idx].InitEvent(eventType, o);
+ _pageCurr![idx].InitEvent(eventType, o);
}
private int NewEvent()
@@ -551,7 +552,7 @@ private int NewEvent()
_singleText.Clear();
}
}
- else if (_pageSize >= _pageCurr.Length)
+ else if (_pageSize >= _pageCurr!.Length)
{
// Create new page
_pageCurr = new XmlEvent[_pageSize * 2];
@@ -588,30 +589,30 @@ private static byte[] ToBytes(byte[] buffer, int index, int count)
private struct XmlEvent
{
private XmlEventType _eventType;
- private string _s1;
- private string _s2;
- private string _s3;
- private object _o;
+ private string? _s1;
+ private string? _s2;
+ private string? _s3;
+ private object? _o;
public void InitEvent(XmlEventType eventType)
{
_eventType = eventType;
}
- public void InitEvent(XmlEventType eventType, string s1)
+ public void InitEvent(XmlEventType eventType, string? s1)
{
_eventType = eventType;
_s1 = s1;
}
- public void InitEvent(XmlEventType eventType, string s1, string s2)
+ public void InitEvent(XmlEventType eventType, string? s1, string? s2)
{
_eventType = eventType;
_s1 = s1;
_s2 = s2;
}
- public void InitEvent(XmlEventType eventType, string s1, string s2, string s3)
+ public void InitEvent(XmlEventType eventType, string? s1, string? s2, string? s3)
{
_eventType = eventType;
_s1 = s1;
@@ -619,7 +620,7 @@ public void InitEvent(XmlEventType eventType, string s1, string s2, string s3)
_s3 = s3;
}
- public void InitEvent(XmlEventType eventType, string s1, string s2, string s3, object o)
+ public void InitEvent(XmlEventType eventType, string? s1, string? s2, string? s3, object? o)
{
_eventType = eventType;
_s1 = s1;
@@ -628,7 +629,7 @@ public void InitEvent(XmlEventType eventType, string s1, string s2, string s3, o
_o = o;
}
- public void InitEvent(XmlEventType eventType, object o)
+ public void InitEvent(XmlEventType eventType, object? o)
{
_eventType = eventType;
_o = o;
@@ -639,22 +640,22 @@ public XmlEventType EventType
get { return _eventType; }
}
- public string String1
+ public string? String1
{
get { return _s1; }
}
- public string String2
+ public string? String2
{
get { return _s2; }
}
- public string String3
+ public string? String3
{
get { return _s3; }
}
- public object Object
+ public object? Object
{
get { return _o; }
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.Unix.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.Unix.cs
index bc856150e1304..04ecc7af51dc1 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.Unix.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.Unix.cs
@@ -7,7 +7,7 @@ namespace System.Xml
{
internal partial class XmlTextReaderImpl
{
- static partial void ConvertAbsoluteUnixPathToAbsoluteUri(ref string url, XmlResolver? resolver)
+ static partial void ConvertAbsoluteUnixPathToAbsoluteUri(ref string? url, XmlResolver? resolver)
{
// new Uri(uri, UriKind.RelativeOrAbsolute) returns a Relative Uri for absolute unix paths (e.g. /tmp).
// We convert the native unix path to a 'file://' uri string to make it an Absolute Uri.
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs
index 7b181e4b798bb..684191a742324 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs
@@ -463,7 +463,7 @@ internal XmlTextReaderImpl(Stream input, XmlNameTable nt) : this(string.Empty, i
{
}
- internal XmlTextReaderImpl(string url, Stream input, XmlNameTable nt) : this(nt)
+ internal XmlTextReaderImpl(string? url, Stream input, XmlNameTable nt) : this(nt)
{
ConvertAbsoluteUnixPathToAbsoluteUri(ref url, resolver: null);
_namespaceManager = new XmlNamespaceManager(nt);
@@ -495,7 +495,7 @@ internal XmlTextReaderImpl(TextReader input, XmlNameTable nt) : this(string.Empt
{
}
- internal XmlTextReaderImpl(string url, TextReader input, XmlNameTable nt) : this(nt)
+ internal XmlTextReaderImpl(string? url, TextReader input, XmlNameTable nt) : this(nt)
{
ConvertAbsoluteUnixPathToAbsoluteUri(ref url, resolver: null);
_namespaceManager = new XmlNamespaceManager(nt);
@@ -695,7 +695,7 @@ private void FinishInitUriString()
// Initializes a new instance of the XmlTextReaderImpl class with the specified arguments.
// This constructor is used when creating XmlTextReaderImpl via XmlReader.Create
- internal XmlTextReaderImpl(Stream stream, byte[]? bytes, int byteCount, XmlReaderSettings settings, Uri? baseUri, string baseUriStr,
+ internal XmlTextReaderImpl(Stream stream, byte[]? bytes, int byteCount, XmlReaderSettings settings, Uri? baseUri, string? baseUriStr,
XmlParserContext? context, bool closeInput)
: this(settings.GetXmlResolver(), settings, context)
{
@@ -707,7 +707,7 @@ internal XmlTextReaderImpl(Stream stream, byte[]? bytes, int byteCount, XmlReade
if (context.BaseURI != null && context.BaseURI.Length > 0 &&
!UriEqual(baseUri, baseUriStr, context.BaseURI, settings.GetXmlResolver()))
{
- if (baseUriStr.Length > 0)
+ if (baseUriStr!.Length > 0)
{
Throw(SR.Xml_DoubleBaseUri);
}
@@ -769,7 +769,7 @@ private void FinishInitStream()
// Initializes a new instance of the XmlTextReaderImpl class with the specified arguments.
// This constructor is used when creating XmlTextReaderImpl via XmlReader.Create
- internal XmlTextReaderImpl(TextReader input, XmlReaderSettings settings, string baseUriStr, XmlParserContext? context)
+ internal XmlTextReaderImpl(TextReader input, XmlReaderSettings settings, string? baseUriStr, XmlParserContext? context)
: this(settings.GetXmlResolver(), settings, context)
{
ConvertAbsoluteUnixPathToAbsoluteUri(ref baseUriStr, settings.GetXmlResolver());
@@ -2477,7 +2477,7 @@ internal bool DtdParserProxy_IsEof
}
}
- internal char[]? DtdParserProxy_ParsingBuffer
+ internal char[] DtdParserProxy_ParsingBuffer
{
get
{
@@ -2560,18 +2560,18 @@ internal int DtdParserProxy_ReadData()
return this.ReadData();
}
- internal int DtdParserProxy_ParseNumericCharRef(StringBuilder internalSubsetBuilder)
+ internal int DtdParserProxy_ParseNumericCharRef(StringBuilder? internalSubsetBuilder)
{
EntityType entType;
return this.ParseNumericCharRef(true, internalSubsetBuilder, out entType);
}
- internal int DtdParserProxy_ParseNamedCharRef(bool expand, StringBuilder internalSubsetBuilder)
+ internal int DtdParserProxy_ParseNamedCharRef(bool expand, StringBuilder? internalSubsetBuilder)
{
return this.ParseNamedCharRef(expand, internalSubsetBuilder);
}
- internal void DtdParserProxy_ParsePI(StringBuilder sb)
+ internal void DtdParserProxy_ParsePI(StringBuilder? sb)
{
if (sb == null)
{
@@ -2586,7 +2586,7 @@ internal void DtdParserProxy_ParsePI(StringBuilder sb)
}
}
- internal void DtdParserProxy_ParseComment(StringBuilder sb)
+ internal void DtdParserProxy_ParseComment(StringBuilder? sb)
{
Debug.Assert(_parsingMode == ParsingMode.Full);
@@ -2725,6 +2725,7 @@ internal void DtdParserProxy_PushInternalDtd(string baseUri, string internalDtd)
_ps.eolNormalized = false;
}
+ [DoesNotReturn]
internal void DtdParserProxy_Throw(Exception e)
{
this.Throw(e);
@@ -8251,7 +8252,7 @@ private bool PushExternalEntity(IDtdEntityInfo entity)
Encoding? enc = _ps.encoding;
PushParsingState();
- InitStringInput(entity.SystemId, enc, string.Empty);
+ InitStringInput(entity.SystemId!, enc, string.Empty);
RegisterEntity(entity);
@@ -8269,7 +8270,7 @@ private void PushInternalEntity(IDtdEntityInfo entity)
PushParsingState();
- InitStringInput(entity.DeclaredUriString ?? string.Empty, enc, entity.Text);
+ InitStringInput(entity.DeclaredUriString ?? string.Empty, enc, entity.Text!);
RegisterEntity(entity);
@@ -8278,7 +8279,7 @@ private void PushInternalEntity(IDtdEntityInfo entity)
_ps.eolNormalized = true;
- RegisterConsumedCharacters(entity.Text.Length, true);
+ RegisterConsumedCharacters(entity.Text!.Length, true);
}
private void PopEntity()
@@ -9746,7 +9747,7 @@ private void InitBinHexDecoder()
}
// SxS: URIs are resolved only to be compared. No resource exposure. It's OK to suppress the SxS warning.
- private bool UriEqual(Uri? uri1, string uri1Str, string uri2Str, XmlResolver? resolver)
+ private bool UriEqual(Uri? uri1, string? uri1Str, string? uri2Str, XmlResolver? resolver)
{
if (resolver == null)
{
@@ -9996,6 +9997,6 @@ internal static void BlockCopy(byte[] src, int srcOffset, byte[] dst, int dstOff
Buffer.BlockCopy(src, srcOffset, dst, dstOffset, count);
}
- static partial void ConvertAbsoluteUnixPathToAbsoluteUri(ref string url, XmlResolver? resolver);
+ static partial void ConvertAbsoluteUnixPathToAbsoluteUri(ref string? url, XmlResolver? resolver);
}
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs
index 50a457599f8f0..72fa4181b4f6a 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.IO;
using System.Text;
@@ -57,7 +58,7 @@ private async Task _GetValueAsync()
private Task FinishInitAsync()
{
- switch (_laterInitParam.initType)
+ switch (_laterInitParam!.initType)
{
case InitInputType.UriString:
return FinishInitUriStringAsync();
@@ -75,14 +76,14 @@ private Task FinishInitAsync()
private async Task FinishInitUriStringAsync()
{
- Stream stream = (Stream)(await _laterInitParam.inputUriResolver.GetEntityAsync(_laterInitParam.inputbaseUri, string.Empty, typeof(Stream)).ConfigureAwait(false));
+ Stream stream = (Stream)(await _laterInitParam!.inputUriResolver!.GetEntityAsync(_laterInitParam.inputbaseUri!, string.Empty, typeof(Stream)).ConfigureAwait(false));
if (stream == null)
{
throw new XmlException(SR.Xml_CannotResolveUrl, _laterInitParam.inputUriStr);
}
- Encoding enc = null;
+ Encoding? enc = null;
// get Encoding from XmlParserContext
if (_laterInitParam.inputContext != null)
{
@@ -92,6 +93,7 @@ private async Task FinishInitUriStringAsync()
try
{
// init ParsingState
+ Debug.Assert(_reportedBaseUri != null);
await InitStreamInputAsync(_laterInitParam.inputbaseUri, _reportedBaseUri, stream, null, 0, enc).ConfigureAwait(false);
_reportedEncoding = _ps.encoding;
@@ -113,16 +115,17 @@ private async Task FinishInitUriStringAsync()
private async Task FinishInitStreamAsync()
{
- Encoding enc = null;
+ Encoding? enc = null;
// get Encoding from XmlParserContext
- if (_laterInitParam.inputContext != null)
+ if (_laterInitParam!.inputContext != null)
{
enc = _laterInitParam.inputContext.Encoding;
}
// init ParsingState
- await InitStreamInputAsync(_laterInitParam.inputbaseUri, _reportedBaseUri, _laterInitParam.inputStream, _laterInitParam.inputBytes, _laterInitParam.inputByteCount, enc).ConfigureAwait(false);
+ Debug.Assert(_reportedBaseUri != null);
+ await InitStreamInputAsync(_laterInitParam.inputbaseUri, _reportedBaseUri, _laterInitParam!.inputStream!, _laterInitParam.inputBytes, _laterInitParam.inputByteCount, enc).ConfigureAwait(false);
_reportedEncoding = _ps.encoding;
@@ -137,7 +140,7 @@ private async Task FinishInitStreamAsync()
private async Task FinishInitTextReaderAsync()
{
// init ParsingState
- await InitTextReaderInputAsync(_reportedBaseUri, _laterInitParam.inputTextReader).ConfigureAwait(false);
+ await InitTextReaderInputAsync(_reportedBaseUri!, _laterInitParam!.inputTextReader!).ConfigureAwait(false);
_reportedEncoding = _ps.encoding;
@@ -901,7 +904,7 @@ internal async Task DtdParserProxy_PushExternalSubsetAsync(string systemId
// Resolve base URI
if (_ps.baseUri == null && !string.IsNullOrEmpty(_ps.baseUriStr))
{
- _ps.baseUri = _xmlResolver.ResolveUri(null, _ps.baseUriStr);
+ _ps.baseUri = _xmlResolver!.ResolveUri(null, _ps.baseUriStr);
}
await PushExternalEntityOrSubsetAsync(publicId, systemId, _ps.baseUri, null).ConfigureAwait(false);
@@ -922,13 +925,13 @@ internal async Task DtdParserProxy_PushExternalSubsetAsync(string systemId
return true;
}
- private Task InitStreamInputAsync(Uri baseUri, Stream stream, Encoding encoding)
+ private Task InitStreamInputAsync(Uri baseUri, Stream stream, Encoding? encoding)
{
Debug.Assert(baseUri != null);
return InitStreamInputAsync(baseUri, baseUri.ToString(), stream, null, 0, encoding);
}
- private async Task InitStreamInputAsync(Uri baseUri, string baseUriStr, Stream stream, byte[] bytes, int byteCount, Encoding encoding)
+ private async Task InitStreamInputAsync(Uri? baseUri, string baseUriStr, Stream stream, byte[]? bytes, int byteCount, Encoding? encoding)
{
Debug.Assert(_ps.charPos == 0 && _ps.charsUsed == 0 && _ps.textReader == null);
Debug.Assert(baseUriStr != null);
@@ -1007,7 +1010,7 @@ private Task InitTextReaderInputAsync(string baseUriStr, TextReader input)
return InitTextReaderInputAsync(baseUriStr, null, input);
}
- private Task InitTextReaderInputAsync(string baseUriStr, Uri baseUri, TextReader input)
+ private Task InitTextReaderInputAsync(string baseUriStr, Uri? baseUri, TextReader input)
{
Debug.Assert(_ps.charPos == 0 && _ps.charsUsed == 0 && _ps.stream == null);
Debug.Assert(baseUriStr != null);
@@ -1066,7 +1069,7 @@ private Task ProcessDtdFromParserContextAsync(XmlParserContext context)
// Switches the reader's encoding
private Task SwitchEncodingAsync(Encoding newEncoding)
{
- if ((newEncoding.WebName != _ps.encoding.WebName || _ps.decoder is SafeAsciiDecoder) && !_afterResetState)
+ if ((newEncoding.WebName != _ps.encoding!.WebName || _ps.decoder is SafeAsciiDecoder) && !_afterResetState)
{
Debug.Assert(_ps.stream != null);
UnDecodeChars();
@@ -1118,7 +1121,7 @@ private async Task ReadDataAsync()
// the byte buffer is full -> allocate a new one
if (_ps.bytesUsed - _ps.bytePos < MaxByteSequenceLen)
{
- if (_ps.bytes.Length - _ps.bytesUsed < MaxByteSequenceLen)
+ if (_ps.bytes!.Length - _ps.bytesUsed < MaxByteSequenceLen)
{
byte[] newBytes = new byte[_ps.bytes.Length * 2];
BlockCopy(_ps.bytes, 0, newBytes, 0, _ps.bytesUsed);
@@ -1176,7 +1179,7 @@ private async Task ReadDataAsync()
}
else
{
- BlockCopy(_ps.bytes, _ps.bytePos, _ps.bytes, 0, bytesLeft);
+ BlockCopy(_ps.bytes!, _ps.bytePos, _ps.bytes!, 0, bytesLeft);
_ps.bytesUsed = bytesLeft;
}
_ps.bytePos = 0;
@@ -1190,7 +1193,7 @@ private async Task ReadDataAsync()
if (!_ps.isStreamEof)
{
// read new bytes
- if (_ps.bytePos == _ps.bytesUsed && _ps.bytes.Length - _ps.bytesUsed > 0)
+ if (_ps.bytePos == _ps.bytesUsed && _ps.bytes!.Length - _ps.bytesUsed > 0)
{
int read = await _ps.stream.ReadAsync(_ps.bytes.AsMemory(_ps.bytesUsed)).ConfigureAwait(false);
if (read == 0)
@@ -1267,7 +1270,7 @@ private async Task ParseXmlDeclarationAsync(bool isTextDecl)
// parse version, encoding & standalone attributes
int xmlDeclState = 0; //
- Encoding encoding = null;
+ Encoding? encoding = null;
while (true)
{
@@ -1307,7 +1310,7 @@ private async Task ParseXmlDeclarationAsync(bool isTextDecl)
if (_afterResetState)
{
// check for invalid encoding switches to default encoding
- string encodingName = _ps.encoding.WebName;
+ string encodingName = _ps.encoding!.WebName;
if (encodingName != "utf-8" && encodingName != "utf-16" &&
encodingName != "utf-16BE" && !(_ps.encoding is Ucs4Encoding))
{
@@ -1344,7 +1347,7 @@ private async Task ParseXmlDeclarationAsync(bool isTextDecl)
// read attribute name
int nameEndPos = await ParseNameAsync().ConfigureAwait(false);
- NodeData attr = null;
+ NodeData? attr = null;
switch (_ps.chars[_ps.charPos])
{
case 'v':
@@ -1387,7 +1390,7 @@ private async Task ParseXmlDeclarationAsync(bool isTextDecl)
}
if (!isTextDecl)
{
- attr.SetLineInfo(_ps.LineNo, _ps.LinePos);
+ attr!.SetLineInfo(_ps.LineNo, _ps.LinePos);
}
sb.Append(_ps.chars, _ps.charPos, nameEndPos - _ps.charPos);
_ps.charPos = nameEndPos;
@@ -1418,7 +1421,7 @@ private async Task ParseXmlDeclarationAsync(bool isTextDecl)
_ps.charPos++;
if (!isTextDecl)
{
- attr.quoteChar = quoteChar;
+ attr!.quoteChar = quoteChar;
attr.SetLineInfo2(_ps.LineNo, _ps.LinePos);
}
@@ -1452,7 +1455,7 @@ private async Task ParseXmlDeclarationAsync(bool isTextDecl)
#endif
if (!isTextDecl)
{
- attr.SetValue(_ps.chars, _ps.charPos, pos - _ps.charPos);
+ attr!.SetValue(_ps.chars, _ps.charPos, pos - _ps.charPos);
}
xmlDeclState = 1;
}
@@ -1467,7 +1470,7 @@ private async Task ParseXmlDeclarationAsync(bool isTextDecl)
encoding = CheckEncoding(encName);
if (!isTextDecl)
{
- attr.SetValue(encName);
+ attr!.SetValue(encName);
}
xmlDeclState = 2;
break;
@@ -1487,7 +1490,7 @@ private async Task ParseXmlDeclarationAsync(bool isTextDecl)
}
if (!isTextDecl)
{
- attr.SetValue(_ps.chars, _ps.charPos, pos - _ps.charPos);
+ attr!.SetValue(_ps.chars, _ps.charPos, pos - _ps.charPos);
}
xmlDeclState = 3;
break;
@@ -1533,7 +1536,7 @@ private async Task ParseXmlDeclarationAsync(bool isTextDecl)
if (_afterResetState)
{
// check for invalid encoding switches to default encoding
- string encodingName = _ps.encoding.WebName;
+ string encodingName = _ps.encoding!.WebName;
if (encodingName != "utf-8" && encodingName != "utf-16" &&
encodingName != "utf-16BE" && !(_ps.encoding is Ucs4Encoding))
{
@@ -2048,7 +2051,7 @@ private Task ParseElementAsync_SetElement(int colonPos, int pos)
char[] chars = _ps.chars;
// push namespace context
- _namespaceManager.PushScope();
+ _namespaceManager!.PushScope();
// init the NodeData class
if (colonPos == -1 || !_supportNamespaces)
@@ -2409,7 +2412,7 @@ private async Task ParseAttributesAsync()
{
int pos = _ps.charPos;
char[] chars = _ps.chars;
- NodeData attr = null;
+ NodeData? attr = null;
Debug.Assert(_attrCount == 0);
@@ -2727,7 +2730,7 @@ private async Task ParseAttributeValueSlowAsync(int curPos, char quoteChar, Node
// Needed only for XmlTextReader (reporting of entities)
int valueChunkStartPos = 0;
LineInfo valueChunkLineInfo = new LineInfo(_ps.lineNo, _ps.LinePos);
- NodeData lastChunk = null;
+ NodeData? lastChunk = null;
Debug.Assert(_stringBuilder.Length == 0);
@@ -2890,7 +2893,7 @@ private async Task ParseAttributeValueSlowAsync(int curPos, char quoteChar, Node
NodeData entityChunk = new NodeData();
entityChunk.lineInfo = entityLineInfo;
entityChunk.depth = attr.depth + 1;
- entityChunk.SetNamedNode(XmlNodeType.EntityReference, _ps.entity.Name);
+ entityChunk.SetNamedNode(XmlNodeType.EntityReference, _ps.entity!.Name);
AddAttributeChunkToList(attr, entityChunk, ref lastChunk);
_fullAttrCleanup = true;
@@ -3060,7 +3063,7 @@ private Task ParseTextAsync()
// Returns true if a node has been parsed and its data set to curNode.
// Returns false when a whitespace has been parsed and ignored (according to current whitespace handling) or when parsing mode is not Full.
// Also returns false if there is no text to be parsed.
- private async Task _ParseTextAsync(Task<(int, int, int, bool)> parseTask)
+ private async Task _ParseTextAsync(Task<(int, int, int, bool)>? parseTask)
{
int startPos;
int endPos;
@@ -3930,7 +3933,7 @@ private async Task ParseEntityReferenceAsync()
// return false == unexpanded external entity, stop parsing and return
private async Task HandleGeneralEntityReferenceAsync(string name, bool isInAttributeValue, bool pushFakeEntityIfNullResolver, int entityStartLinePos)
{
- IDtdEntityInfo entity = null;
+ IDtdEntityInfo? entity = null;
if (_dtdInfo == null && _fragmentParserContext != null && _fragmentParserContext.HasDtdInfo && _dtdProcessing == DtdProcessing.Parse)
{
@@ -4020,7 +4023,7 @@ private Task ParsePIAsync()
// Parses processing instruction; if piInDtdStringBuilder != null, the processing instruction is in DTD and
// it will be saved in the passed string builder (target, whitespace & value).
- private async Task ParsePIAsync(StringBuilder piInDtdStringBuilder)
+ private async Task ParsePIAsync(StringBuilder? piInDtdStringBuilder)
{
if (_parsingMode == ParsingMode.Full)
{
@@ -4928,7 +4931,7 @@ private async Task SkipUntilAsync(char stopChar, bool recognizeLiterals)
}
}
- private async Task EatWhitespacesAsync(StringBuilder sb)
+ private async Task EatWhitespacesAsync(StringBuilder? sb)
{
int pos = _ps.charPos;
int wsCount = 0;
@@ -5035,7 +5038,7 @@ private async Task EatWhitespacesAsync(StringBuilder sb)
// - returns position of the end of the character reference, that is of the character next to the original ';'
// - if (expand == true) then ps.charPos is changed to point to the replaced character
- private async Task<(EntityType, int)> ParseNumericCharRefAsync(bool expand, StringBuilder internalSubsetBuilder)
+ private async Task<(EntityType, int)> ParseNumericCharRefAsync(bool expand, StringBuilder? internalSubsetBuilder)
{
EntityType entityType;
@@ -5070,7 +5073,7 @@ private async Task EatWhitespacesAsync(StringBuilder sb)
// - replaces the last character of the entity reference (';') with the referenced character (if expand == true)
// - returns position of the end of the character reference, that is of the character next to the original ';'
// - if (expand == true) then ps.charPos is changed to point to the replaced character
- private async Task ParseNamedCharRefAsync(bool expand, StringBuilder internalSubsetBuilder)
+ private async Task ParseNamedCharRefAsync(bool expand, StringBuilder? internalSubsetBuilder)
{
while (true)
{
@@ -5246,7 +5249,7 @@ private async Task ParseEntityNameAsync()
// This method resolves and opens an external DTD subset or an external entity based on its SYSTEM or PUBLIC ID.
// SxS: This method may expose a name if a resource in baseUri (ref) parameter.
- private async Task PushExternalEntityOrSubsetAsync(string publicId, string systemId, Uri baseUri, string entityName)
+ private async Task PushExternalEntityOrSubsetAsync(string? publicId, string? systemId, Uri? baseUri, string? entityName)
{
Uri uri;
@@ -5255,7 +5258,7 @@ private async Task PushExternalEntityOrSubsetAsync(string publicId, string syste
{
try
{
- uri = _xmlResolver.ResolveUri(baseUri, publicId);
+ uri = _xmlResolver!.ResolveUri(baseUri, publicId);
if (await OpenAndPushAsync(uri).ConfigureAwait(false))
{
return;
@@ -5268,7 +5271,7 @@ private async Task PushExternalEntityOrSubsetAsync(string publicId, string syste
}
// Then try SYSTEM Id
- uri = _xmlResolver.ResolveUri(baseUri, systemId);
+ uri = _xmlResolver!.ResolveUri(baseUri, systemId);
try
{
if (await OpenAndPushAsync(uri).ConfigureAwait(false))
@@ -5290,7 +5293,7 @@ private async Task PushExternalEntityOrSubsetAsync(string publicId, string syste
if (entityName == null)
{
- ThrowWithoutLineInfo(SR.Xml_CannotResolveExternalSubset, new string[] { (publicId != null ? publicId : string.Empty), systemId }, null);
+ ThrowWithoutLineInfo(SR.Xml_CannotResolveExternalSubset, new string?[] { (publicId != null ? publicId : string.Empty), systemId }, null);
}
else
{
@@ -5347,11 +5350,11 @@ private async Task PushExternalEntityAsync(IDtdEntityInfo entity)
if (!IsResolverNull)
{
- Uri entityBaseUri = null;
+ Uri? entityBaseUri = null;
// Resolve base URI
if (!string.IsNullOrEmpty(entity.BaseUriString))
{
- entityBaseUri = _xmlResolver.ResolveUri(null, entity.BaseUriString);
+ entityBaseUri = _xmlResolver!.ResolveUri(null, entity.BaseUriString);
}
await PushExternalEntityOrSubsetAsync(entity.PublicId, entity.SystemId, entityBaseUri, entity.Name).ConfigureAwait(false);
@@ -5371,10 +5374,10 @@ private async Task PushExternalEntityAsync(IDtdEntityInfo entity)
}
else
{
- Encoding enc = _ps.encoding;
+ Encoding? enc = _ps.encoding;
PushParsingState();
- InitStringInput(entity.SystemId, enc, string.Empty);
+ InitStringInput(entity.SystemId!, enc, string.Empty);
RegisterEntity(entity);
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpers.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpers.cs
index cea09b331e336..be5a76394eb4e 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpers.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpers.cs
@@ -26,7 +26,7 @@ internal partial class XmlTextReaderImpl
private struct ParsingState
{
// character buffer
- internal char[]? chars;
+ internal char[] chars;
internal int charPos;
internal int charsUsed;
internal Encoding? encoding;
@@ -66,7 +66,7 @@ private struct ParsingState
internal void Clear()
{
- chars = null;
+ chars = null!;
charPos = 0;
charsUsed = 0;
encoding = null;
@@ -200,7 +200,7 @@ bool IDtdParserAdapter.IsEof
get { return _reader.DtdParserProxy_IsEof; }
}
- char[]? IDtdParserAdapter.ParsingBuffer
+ char[] IDtdParserAdapter.ParsingBuffer
{
get { return _reader.DtdParserProxy_ParsingBuffer; }
}
@@ -246,22 +246,22 @@ int IDtdParserAdapter.ReadData()
return _reader.DtdParserProxy_ReadData();
}
- int IDtdParserAdapter.ParseNumericCharRef(StringBuilder internalSubsetBuilder)
+ int IDtdParserAdapter.ParseNumericCharRef(StringBuilder? internalSubsetBuilder)
{
return _reader.DtdParserProxy_ParseNumericCharRef(internalSubsetBuilder);
}
- int IDtdParserAdapter.ParseNamedCharRef(bool expand, StringBuilder internalSubsetBuilder)
+ int IDtdParserAdapter.ParseNamedCharRef(bool expand, StringBuilder? internalSubsetBuilder)
{
return _reader.DtdParserProxy_ParseNamedCharRef(expand, internalSubsetBuilder);
}
- void IDtdParserAdapter.ParsePI(StringBuilder sb)
+ void IDtdParserAdapter.ParsePI(StringBuilder? sb)
{
_reader.DtdParserProxy_ParsePI(sb);
}
- void IDtdParserAdapter.ParseComment(StringBuilder sb)
+ void IDtdParserAdapter.ParseComment(StringBuilder? sb)
{
_reader.DtdParserProxy_ParseComment(sb);
}
@@ -276,7 +276,7 @@ bool IDtdParserAdapter.PopEntity(out IDtdEntityInfo? oldEntity, out int newEntit
return _reader.DtdParserProxy_PopEntity(out oldEntity, out newEntityId);
}
- bool IDtdParserAdapter.PushExternalSubset(string systemId, string publicId)
+ bool IDtdParserAdapter.PushExternalSubset(string? systemId, string? publicId)
{
return _reader.DtdParserProxy_PushExternalSubset(systemId, publicId);
}
@@ -287,6 +287,7 @@ void IDtdParserAdapter.PushInternalDtd(string baseUri, string internalDtd)
_reader.DtdParserProxy_PushInternalDtd(baseUri, internalDtd);
}
+ [DoesNotReturn]
void IDtdParserAdapter.Throw(Exception e)
{
_reader.DtdParserProxy_Throw(e);
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpersAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpersAsync.cs
index ee608883fa79b..a062d03735bf5 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpersAsync.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpersAsync.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.IO;
using System.Text;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingReader.cs
index 28d90db3e1719..28966fbb4c52c 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingReader.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingReader.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.Xml;
using System.Xml.Schema;
@@ -16,7 +17,7 @@ internal partial class XmlWrappingReader : XmlReader, IXmlLineInfo
// Fields
//
protected XmlReader reader;
- protected IXmlLineInfo readerAsIXmlLineInfo;
+ protected IXmlLineInfo? readerAsIXmlLineInfo;
//
// Constructor
@@ -31,7 +32,7 @@ internal XmlWrappingReader(XmlReader baseReader)
//
// XmlReader implementation
//
- public override XmlReaderSettings Settings { get { return reader.Settings; } }
+ public override XmlReaderSettings? Settings { get { return reader.Settings; } }
public override XmlNodeType NodeType { get { return reader.NodeType; } }
public override string Name { get { return reader.Name; } }
public override string LocalName { get { return reader.LocalName; } }
@@ -40,7 +41,7 @@ internal XmlWrappingReader(XmlReader baseReader)
public override bool HasValue { get { return reader.HasValue; } }
public override string Value { get { return reader.Value; } }
public override int Depth { get { return reader.Depth; } }
- public override string BaseURI { get { return reader.BaseURI; } }
+ public override string? BaseURI { get { return reader.BaseURI; } }
public override bool IsEmptyElement { get { return reader.IsEmptyElement; } }
public override bool IsDefault { get { return reader.IsDefault; } }
public override XmlSpace XmlSpace { get { return reader.XmlSpace; } }
@@ -53,15 +54,15 @@ internal XmlWrappingReader(XmlReader baseReader)
public override XmlNameTable NameTable { get { return reader.NameTable; } }
public override bool CanResolveEntity { get { return reader.CanResolveEntity; } }
- public override IXmlSchemaInfo SchemaInfo { get { return reader.SchemaInfo; } }
+ public override IXmlSchemaInfo? SchemaInfo { get { return reader.SchemaInfo; } }
public override char QuoteChar { get { return reader.QuoteChar; } }
- public override string GetAttribute(string name)
+ public override string? GetAttribute(string name)
{
return reader.GetAttribute(name);
}
- public override string GetAttribute(string name, string namespaceURI)
+ public override string? GetAttribute(string name, string namespaceURI)
{
return reader.GetAttribute(name, namespaceURI);
}
@@ -116,7 +117,7 @@ public override void Skip()
reader.Skip();
}
- public override string LookupNamespace(string prefix)
+ public override string? LookupNamespace(string prefix)
{
return reader.LookupNamespace(prefix);
}
@@ -158,7 +159,7 @@ public virtual int LinePosition
//
// Internal methods
//
- internal override IDtdInfo DtdInfo
+ internal override IDtdInfo? DtdInfo
{
get
{
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingReaderAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingReaderAsync.cs
index c5573cb5658b3..501718f0cd0bf 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingReaderAsync.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingReaderAsync.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.Xml;
using System.Xml.Schema;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingWriterAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingWriterAsync.cs
index 332dad4d9e01f..05519fa8d486a 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingWriterAsync.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWrappingWriterAsync.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.IO;
using System.Xml.Schema;
@@ -29,12 +30,12 @@ public override Task WriteEndDocumentAsync()
return writer.WriteEndDocumentAsync();
}
- public override Task WriteDocTypeAsync(string name, string pubid, string sysid, string subset)
+ public override Task WriteDocTypeAsync(string name, string? pubid, string? sysid, string subset)
{
return writer.WriteDocTypeAsync(name, pubid, sysid, subset);
}
- public override Task WriteStartElementAsync(string prefix, string localName, string ns)
+ public override Task WriteStartElementAsync(string? prefix, string localName, string? ns)
{
return writer.WriteStartElementAsync(prefix, localName, ns);
}
@@ -49,7 +50,7 @@ public override Task WriteFullEndElementAsync()
return writer.WriteFullEndElementAsync();
}
- protected internal override Task WriteStartAttributeAsync(string prefix, string localName, string ns)
+ protected internal override Task WriteStartAttributeAsync(string? prefix, string localName, string? ns)
{
return writer.WriteStartAttributeAsync(prefix, localName, ns);
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdCachingReaderAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdCachingReaderAsync.cs
index 724e58d7d55ab..6d4d5ecf0e39f 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdCachingReaderAsync.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdCachingReaderAsync.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.IO;
using System.Text;
using System.Xml.Schema;
@@ -39,7 +40,7 @@ public override async Task ReadAsync()
goto case CachingReaderState.Record;
case CachingReaderState.Record:
- ValidatingReaderNodeData recordedNode = null;
+ ValidatingReaderNodeData? recordedNode = null;
if (await _coreReader.ReadAsync().ConfigureAwait(false))
{
switch (_coreReader.NodeType)
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReader.cs
index 2115a780f0dd9..e49c541d6d9e8 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReader.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReader.cs
@@ -2386,7 +2386,7 @@ private object InternalReadContentAsObject(bool unwrapTypedValue, out string ori
if (_validationState == ValidatingReaderState.OnDefaultAttribute)
{
XmlSchemaAttribute schemaAttr = _attributePSVI.attributeSchemaInfo.SchemaAttribute;
- originalStringValue = (schemaAttr.DefaultValue != null) ? schemaAttr.DefaultValue : schemaAttr.FixedValue;
+ originalStringValue = (schemaAttr.DefaultValue != null) ? schemaAttr.DefaultValue : schemaAttr.FixedValue!;
}
return ReturnBoxedValue(_attributePSVI.typedAttributeValue, AttributeSchemaInfo.XmlType, unwrapTypedValue)!;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReaderAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReaderAsync.cs
index a9953d2873af4..7b6dd7568423c 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReaderAsync.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReaderAsync.cs
@@ -699,7 +699,7 @@ private async Task> InternalReadContentAsObjectTupleAsync(
if (_validationState == ValidatingReaderState.OnDefaultAttribute)
{
XmlSchemaAttribute schemaAttr = _attributePSVI.attributeSchemaInfo.SchemaAttribute;
- originalStringValue = (schemaAttr.DefaultValue != null) ? schemaAttr.DefaultValue : schemaAttr.FixedValue;
+ originalStringValue = (schemaAttr.DefaultValue != null) ? schemaAttr.DefaultValue : schemaAttr.FixedValue!;
}
tuple = new Tuple(originalStringValue, ReturnBoxedValue(_attributePSVI.typedAttributeValue, AttributeSchemaInfo.XmlType, unwrapTypedValue)!);
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/DiagnosticsSwitches.cs b/src/libraries/System.Private.Xml/src/System/Xml/DiagnosticsSwitches.cs
index 415d1e1a49b9c..2504e4fa181db 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/DiagnosticsSwitches.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/DiagnosticsSwitches.cs
@@ -2,14 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Xml
{
using System.Diagnostics;
internal static class DiagnosticsSwitches
{
- private static volatile BooleanSwitch s_keepTempFiles;
- private static volatile BooleanSwitch s_nonRecursiveTypeLoading;
+ private static volatile BooleanSwitch? s_keepTempFiles;
+ private static volatile BooleanSwitch? s_nonRecursiveTypeLoading;
public static BooleanSwitch KeepTempFiles
{
@@ -19,6 +20,7 @@ public static BooleanSwitch KeepTempFiles
{
s_keepTempFiles = new BooleanSwitch("XmlSerialization.Compilation", "Keep XmlSerialization generated (temp) files.");
}
+
return s_keepTempFiles;
}
}
@@ -31,6 +33,7 @@ public static BooleanSwitch NonRecursiveTypeLoading
{
s_nonRecursiveTypeLoading = new BooleanSwitch("XmlSerialization.NonRecursiveTypeLoading", "Turn on non-recursive algorithm generating XmlMappings for CLR types.");
}
+
return s_nonRecursiveTypeLoading;
}
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/EmptyEnumerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/EmptyEnumerator.cs
index 26d41169e4c06..1a3470879e7f7 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/EmptyEnumerator.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/EmptyEnumerator.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.Collections;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Extensions/ExtensionMethods.cs b/src/libraries/System.Private.Xml/src/System/Xml/Extensions/ExtensionMethods.cs
index 14e328192b887..43ac77f65af2d 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Extensions/ExtensionMethods.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Extensions/ExtensionMethods.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Reflection;
@@ -11,12 +12,12 @@ internal static class ExtensionMethods
{
#region Contract compliance for System.Type
- internal static ConstructorInfo GetConstructor(this Type type, BindingFlags bindingFlags, Type[] parameterTypes)
+ internal static ConstructorInfo? GetConstructor(this Type type, BindingFlags bindingFlags, Type[] parameterTypes)
{
return type.GetConstructor(bindingFlags, null, parameterTypes, null);
}
- internal static MethodInfo GetMethod(this Type type, string methodName, BindingFlags bindingFlags, Type[] parameterTypes)
+ internal static MethodInfo? GetMethod(this Type type, string methodName, BindingFlags bindingFlags, Type[] parameterTypes)
{
return type.GetMethod(methodName, bindingFlags, null, parameterTypes, null);
}
@@ -33,10 +34,11 @@ internal static Uri ToUri(string s)
throw new FormatException(SR.Format(SR.XmlConvert_BadFormat, s, "Uri"));
}
}
- if (!Uri.TryCreate(s, UriKind.RelativeOrAbsolute, out Uri uri))
+ if (!Uri.TryCreate(s, UriKind.RelativeOrAbsolute, out Uri? uri))
{
throw new FormatException(SR.Format(SR.XmlConvert_BadFormat, s, "Uri"));
}
+
return uri;
}
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/HWStack.cs b/src/libraries/System.Private.Xml/src/System/Xml/HWStack.cs
index 4f571403d2088..dfdc18124444e 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/HWStack.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/HWStack.cs
@@ -2,9 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
-
namespace System.Xml
{
// This stack is designed to minimize object creation for the
@@ -35,18 +35,21 @@ internal object Push()
{
throw new XmlException(SR.Xml_StackOverflow, string.Empty);
}
+
object[] newstack = new object[_size + _growthRate];
if (_used > 0)
{
System.Array.Copy(_stack, newstack, _used);
}
+
_stack = newstack;
_size += _growthRate;
}
+
return _stack[_used++];
}
- internal object Pop()
+ internal object? Pop()
{
if (0 < _used)
{
@@ -54,10 +57,11 @@ internal object Pop()
object result = _stack[_used];
return result;
}
+
return null;
}
- internal object Peek()
+ internal object? Peek()
{
return _used > 0 ? _stack[_used - 1] : null;
}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/IApplicationResourceStreamResolver.cs b/src/libraries/System.Private.Xml/src/System/Xml/IApplicationResourceStreamResolver.cs
index ce284aa2dd3fc..9ba64e1b036c9 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/IApplicationResourceStreamResolver.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/IApplicationResourceStreamResolver.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System;
using System.IO;
using System.ComponentModel;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/IHasXmlNode.cs b/src/libraries/System.Private.Xml/src/System/Xml/IHasXmlNode.cs
index 72dfeba7ff800..19a8d6334d2c6 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/IHasXmlNode.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/IHasXmlNode.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Xml
{
public interface IHasXmlNode
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/LineInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/LineInfo.cs
index 1b76b28121f96..a7bf894e659da 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/LineInfo.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/LineInfo.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Xml
{
internal struct LineInfo
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/MTNameTable.cs b/src/libraries/System.Private.Xml/src/System/Xml/MTNameTable.cs
index 052670eb318ec..eadc7abba158e 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/MTNameTable.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/MTNameTable.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
#if MTNAMETABLE
using System;
using System.IO;
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Ref.cs b/src/libraries/System.Private.Xml/src/System/Xml/Ref.cs
index 18ed298d2fd75..056fb3541347a 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Ref.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Ref.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Diagnostics;
namespace System.Xml
@@ -11,13 +12,13 @@ namespace System.Xml
///
internal static class Ref
{
- public static bool Equal(string strA, string strB)
+ public static bool Equal(string? strA, string? strB)
{
#if DEBUG
- if (((object)strA != (object)strB) && string.Equals(strA, strB))
+ if (((object?)strA != (object?)strB) && string.Equals(strA, strB))
Debug.Fail("Ref.Equal: Object comparison used for non-atomized string '" + strA + "'");
#endif
- return (object)strA == (object)strB;
+ return (object?)strA == (object?)strB;
}
// Prevent typos. If someone uses Ref.Equals instead of Ref.Equal,
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlKnownDtds.cs b/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlKnownDtds.cs
index f8f307369be69..5ae750f54f007 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlKnownDtds.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlKnownDtds.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Xml.Resolvers
{
//
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlPreloadedResolverAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlPreloadedResolverAsync.cs
index 62049b77f22a3..3d9ee1c95ac62 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlPreloadedResolverAsync.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Resolvers/XmlPreloadedResolverAsync.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.IO;
using System.Xml;
using System.Threading.Tasks;
@@ -16,7 +17,7 @@ namespace System.Xml.Resolvers
public partial class XmlPreloadedResolver : XmlResolver
{
public override Task