apply another batch of feedback
authorKrzysztof Wicher <kwicher@microsoft.com>
Sat, 25 Apr 2020 02:08:24 +0000 (19:08 -0700)
committerKrzysztof Wicher <kwicher@microsoft.com>
Sat, 25 Apr 2020 02:08:24 +0000 (19:08 -0700)
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlSubtreeReader.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReader.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpers.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWriter.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWriterAsync.cs
src/libraries/System.Private.Xml/src/System/Xml/XmlNamespacemanager.cs

index 8b2c129..9432bb5 100644 (file)
@@ -73,7 +73,7 @@ namespace System.Xml
 
         // namespace management
         private readonly XmlNamespaceManager _nsManager;
-        private NodeData?[]? _nsAttributes;
+        private NodeData[]? _nsAttributes;
         private int _nsAttrCount;
         private int _curNsAttr = -1;
 
@@ -118,7 +118,7 @@ namespace System.Xml
         {
             get
             {
-                return (_useCurNode) ? _curNode.type : reader.NodeType;
+                return _useCurNode ? _curNode.type : reader.NodeType;
             }
         }
 
@@ -126,7 +126,7 @@ namespace System.Xml
         {
             get
             {
-                return _useCurNode ? _curNode.name! : reader.Name;
+                return _useCurNode ? _curNode.name : reader.Name;
             }
         }
 
@@ -134,7 +134,7 @@ namespace System.Xml
         {
             get
             {
-                return (_useCurNode) ? _curNode.localName : reader.LocalName;
+                return _useCurNode ? _curNode.localName : reader.LocalName;
             }
         }
 
@@ -142,7 +142,7 @@ namespace System.Xml
         {
             get
             {
-                return (_useCurNode) ? _curNode.namespaceUri : reader.NamespaceURI;
+                return _useCurNode ? _curNode.namespaceUri : reader.NamespaceURI;
             }
         }
 
@@ -150,7 +150,7 @@ namespace System.Xml
         {
             get
             {
-                return (_useCurNode) ? _curNode.prefix : reader.Prefix;
+                return _useCurNode ? _curNode.prefix : reader.Prefix;
             }
         }
 
@@ -158,7 +158,7 @@ namespace System.Xml
         {
             get
             {
-                return (_useCurNode) ? _curNode.value : reader.Value;
+                return _useCurNode ? _curNode.value : reader.Value;
             }
         }
 
@@ -258,10 +258,10 @@ namespace System.Xml
 
             for (int i = 0; i < _nsAttrCount; i++)
             {
-                if (name == _nsAttributes![i]!.name)
+                if (name == _nsAttributes![i].name)
                 {
                     // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
-                    return _nsAttributes[i]!.value;
+                    return _nsAttributes[i].value;
                 }
             }
             return null;
@@ -282,10 +282,10 @@ namespace System.Xml
 
             for (int i = 0; i < _nsAttrCount; i++)
             {
-                if (name == _nsAttributes![i]!.localName && namespaceURI == _xmlnsUri)
+                if (name == _nsAttributes![i].localName && namespaceURI == _xmlnsUri)
                 {
                     // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
-                    return _nsAttributes[i]!.value;
+                    return _nsAttributes[i].value;
                 }
             }
 
@@ -305,7 +305,7 @@ namespace System.Xml
             }
             else if (i - n < _nsAttrCount)
             {
-                return _nsAttributes![i - n]!.value;
+                return _nsAttributes![i - n].value;
             }
             else
             {
@@ -328,7 +328,7 @@ namespace System.Xml
 
             for (int i = 0; i < _nsAttrCount; i++)
             {
-                if (name == _nsAttributes![i]!.name)
+                if (name == _nsAttributes![i].name)
                 {
                     MoveToNsAttribute(i);
                     return true;
@@ -352,7 +352,7 @@ namespace System.Xml
 
             for (int i = 0; i < _nsAttrCount; i++)
             {
-                if (name == _nsAttributes![i]!.localName && ns == _xmlnsUri)
+                if (name == _nsAttributes![i].localName && ns == _xmlnsUri)
                 {
                     MoveToNsAttribute(i);
                     return true;
@@ -1183,8 +1183,7 @@ namespace System.Xml
             {
                 if (!_useCurNode)
                 {
-                    IXmlLineInfo? lineInfo = reader as IXmlLineInfo;
-                    if (lineInfo != null)
+                    if (reader is IXmlLineInfo lineInfo)
                     {
                         return lineInfo.LineNumber;
                     }
@@ -1199,8 +1198,7 @@ namespace System.Xml
             {
                 if (!_useCurNode)
                 {
-                    IXmlLineInfo? lineInfo = reader as IXmlLineInfo;
-                    if (lineInfo != null)
+                    if (reader is IXmlLineInfo lineInfo)
                     {
                         return lineInfo.LinePosition;
                     }
@@ -1341,7 +1339,7 @@ namespace System.Xml
             }
             else
             {
-                _nsAttributes[index]!.Set(XmlNodeType.Attribute, localName, attrPrefix, name, _xmlnsUri, ns);
+                _nsAttributes[index].Set(XmlNodeType.Attribute, localName, attrPrefix, name, _xmlnsUri, ns);
             }
 
             Debug.Assert(_state == State.ClearNsAttributes || _state == State.Interactive || _state == State.PopNamespaceScope);
@@ -1354,13 +1352,13 @@ namespace System.Xml
         {
             for (int i = 0; i < _nsAttrCount; i++)
             {
-                if (Ref.Equal(prefix, _nsAttributes![i]!.prefix) &&
-                     Ref.Equal(localName, _nsAttributes![i]!.localName)) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
+                if (Ref.Equal(prefix, _nsAttributes![i].prefix) &&
+                     Ref.Equal(localName, _nsAttributes![i].localName)) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
                 {
                     if (i < _nsAttrCount - 1)
                     {
                         // swap
-                        NodeData tmpNodeData = _nsAttributes![i]!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
+                        NodeData tmpNodeData = _nsAttributes![i]; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
                         _nsAttributes[i] = _nsAttributes[_nsAttrCount - 1];
                         _nsAttributes[_nsAttrCount - 1] = tmpNodeData;
                     }
@@ -1376,7 +1374,7 @@ namespace System.Xml
             reader.MoveToElement();
             _curNsAttr = index;
             _nsIncReadOffset = 0;
-            SetCurrentNode(_nsAttributes![index]!);
+            SetCurrentNode(_nsAttributes![index]);
         }
 
         private bool InitReadElementContentAsBinary(State binaryState)
index f984f0a..b8a45ad 100644 (file)
@@ -189,7 +189,7 @@ namespace System.Xml
             return _impl.GetAttribute(name);
         }
 
-        public override string? GetAttribute(string localName, string namespaceURI)
+        public override string? GetAttribute(string localName, string? namespaceURI)
         {
             return _impl.GetAttribute(localName, namespaceURI);
         }
index b2d1396..ae7235e 100644 (file)
@@ -386,7 +386,6 @@ namespace System.Xml
             else
             {
                 SetupFromParserContext(context, settings);
-                Debug.Assert(_nameTable != null);
                 nt = _nameTable;
             }
 
@@ -1119,7 +1118,7 @@ namespace System.Xml
         }
 
         // Moves to an attribute with the specified LocalName and NamespceURI
-        public override bool MoveToAttribute(string localName, string namespaceURI)
+        public override bool MoveToAttribute(string localName, string? namespaceURI)
         {
             string? namespaceURIAtomized = (namespaceURI == null) ? string.Empty : _nameTable.Get(namespaceURI);
             string? localNameAtomized = _nameTable.Get(localName);
@@ -8002,7 +8001,7 @@ namespace System.Xml
             else
             {
                 Throw(SR.Xml_UnknownNs, node.prefix, node.LineNo, node.LinePos);
-                return null!;
+                return null;
             }
         }
 
@@ -9002,11 +9001,11 @@ namespace System.Xml
 
             if (expectedToken2 != null)
             {
-                Throw(SR.Xml_UnexpectedTokens2, new string?[3] { unexpectedToken, expectedToken1, expectedToken2 });
+                Throw(SR.Xml_UnexpectedTokens2, new string[3] { unexpectedToken, expectedToken1, expectedToken2 });
             }
             else
             {
-                Throw(SR.Xml_UnexpectedTokenEx, new string?[2] { unexpectedToken, expectedToken1 });
+                Throw(SR.Xml_UnexpectedTokenEx, new string[2] { unexpectedToken, expectedToken1 });
             }
         }
 
index f411b19..cea09b3 100644 (file)
@@ -755,8 +755,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    IDtdDefaultAttributeInfo? attrDef = x as IDtdDefaultAttributeInfo;
-                    if (attrDef != null)
+                    if (x is IDtdDefaultAttributeInfo attrDef)
                     {
                         localName = attrDef.LocalName;
                         prefix = attrDef.Prefix;
@@ -775,8 +774,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    IDtdDefaultAttributeInfo? attrDef = y as IDtdDefaultAttributeInfo;
-                    if (attrDef != null)
+                    if (y is IDtdDefaultAttributeInfo attrDef)
                     {
                         localName2 = attrDef.LocalName;
                         prefix2 = attrDef.Prefix;
index ceb3eba..d412522 100644 (file)
@@ -591,30 +591,32 @@ namespace System.Xml
         // Element Helper Methods
 
         // Writes out an element with the specified name containing the specified string value.
-        public void WriteElementString(string localName, string value)
+        public void WriteElementString(string localName, string? value)
         {
             WriteElementString(localName, null, value);
         }
 
         // Writes out an attribute with the specified name, namespace URI and string value.
-        public void WriteElementString(string localName, string? ns, string value)
+        public void WriteElementString(string localName, string? ns, string? value)
         {
             WriteStartElement(localName, ns);
             if (null != value && 0 != value.Length)
             {
                 WriteString(value);
             }
+
             WriteEndElement();
         }
 
         // Writes out an attribute with the specified name, namespace URI, and string value.
-        public void WriteElementString(string? prefix, string localName, string? ns, string value)
+        public void WriteElementString(string? prefix, string localName, string? ns, string? value)
         {
             WriteStartElement(prefix, localName, ns);
             if (null != value && 0 != value.Length)
             {
                 WriteString(value);
             }
+
             WriteEndElement();
         }
 
@@ -682,7 +684,7 @@ namespace System.Xml
         }
 
         // Creates an XmlWriter for writing into the provided file with the specified settings.
-        public static XmlWriter Create(string outputFileName, XmlWriterSettings settings)
+        public static XmlWriter Create(string outputFileName, XmlWriterSettings? settings)
         {
             settings ??= XmlWriterSettings.s_defaultWriterSettings;
             return settings.CreateWriter(outputFileName);
@@ -704,7 +706,7 @@ namespace System.Xml
         }
 
         // Creates an XmlWriter for writing into the provided stream with the specified settings.
-        public static XmlWriter Create(Stream output, XmlWriterSettings settings)
+        public static XmlWriter Create(Stream output, XmlWriterSettings? settings)
         {
             settings ??= XmlWriterSettings.s_defaultWriterSettings;
             return settings.CreateWriter(output);
@@ -726,7 +728,7 @@ namespace System.Xml
         }
 
         // Creates an XmlWriter for writing into the provided TextWriter with the specified settings.
-        public static XmlWriter Create(TextWriter output, XmlWriterSettings settings)
+        public static XmlWriter Create(TextWriter output, XmlWriterSettings? settings)
         {
             settings ??= XmlWriterSettings.s_defaultWriterSettings;
             return settings.CreateWriter(output);
@@ -746,7 +748,7 @@ namespace System.Xml
         }
 
         // Creates an XmlWriter for writing into the provided StringBuilder with the specified settings.
-        public static XmlWriter Create(StringBuilder output, XmlWriterSettings settings)
+        public static XmlWriter Create(StringBuilder output, XmlWriterSettings? settings)
         {
             if (output == null)
             {
index 29c1ba4..7e36a62 100644 (file)
@@ -71,7 +71,6 @@ namespace System.Xml
             throw new NotImplementedException();
         }
 
-        // Writes out the attribute with the specified LocalName, value, and NamespaceURI.
         // Writes out the attribute with the specified prefix, LocalName, NamespaceURI and value.
         public Task WriteAttributeStringAsync(string? prefix, string localName, string? ns, string value)
         {
index c7f8f3c..3f1ff9f 100644 (file)
@@ -7,6 +7,7 @@ using System;
 using System.Collections;
 using System.Diagnostics;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 
 namespace System.Xml
 {
@@ -231,10 +232,10 @@ namespace System.Xml
         // This pragma disables a warning that the return type is not CLS-compliant, but generics are part of CLS in Whidbey.
 #pragma warning disable 3002
         public virtual IDictionary<string, string> GetNamespacesInScope(XmlNamespaceScope scope)
+#pragma warning restore 3002
         {
             Debug.Assert(_nsdecls != null);
 
-#pragma warning restore 3002
             int i = 0;
             switch (scope)
             {
@@ -365,7 +366,7 @@ namespace System.Xml
             return false;
         }
 
-        internal bool GetNamespaceDeclaration(int idx, out string? prefix, out string? uri)
+        internal bool GetNamespaceDeclaration(int idx, [NotNullWhen(true)] out string? prefix, out string? uri)
         {
             idx = _lastDecl - idx;
             if (idx < 0)