// namespace management
private readonly XmlNamespaceManager _nsManager;
- private NodeData?[]? _nsAttributes;
+ private NodeData[]? _nsAttributes;
private int _nsAttrCount;
private int _curNsAttr = -1;
{
get
{
- return (_useCurNode) ? _curNode.type : reader.NodeType;
+ return _useCurNode ? _curNode.type : reader.NodeType;
}
}
{
get
{
- return _useCurNode ? _curNode.name! : reader.Name;
+ return _useCurNode ? _curNode.name : reader.Name;
}
}
{
get
{
- return (_useCurNode) ? _curNode.localName : reader.LocalName;
+ return _useCurNode ? _curNode.localName : reader.LocalName;
}
}
{
get
{
- return (_useCurNode) ? _curNode.namespaceUri : reader.NamespaceURI;
+ return _useCurNode ? _curNode.namespaceUri : reader.NamespaceURI;
}
}
{
get
{
- return (_useCurNode) ? _curNode.prefix : reader.Prefix;
+ return _useCurNode ? _curNode.prefix : reader.Prefix;
}
}
{
get
{
- return (_useCurNode) ? _curNode.value : reader.Value;
+ return _useCurNode ? _curNode.value : reader.Value;
}
}
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;
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;
}
}
}
else if (i - n < _nsAttrCount)
{
- return _nsAttributes![i - n]!.value;
+ return _nsAttributes![i - n].value;
}
else
{
for (int i = 0; i < _nsAttrCount; i++)
{
- if (name == _nsAttributes![i]!.name)
+ if (name == _nsAttributes![i].name)
{
MoveToNsAttribute(i);
return true;
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;
{
if (!_useCurNode)
{
- IXmlLineInfo? lineInfo = reader as IXmlLineInfo;
- if (lineInfo != null)
+ if (reader is IXmlLineInfo lineInfo)
{
return lineInfo.LineNumber;
}
{
if (!_useCurNode)
{
- IXmlLineInfo? lineInfo = reader as IXmlLineInfo;
- if (lineInfo != null)
+ if (reader is IXmlLineInfo lineInfo)
{
return lineInfo.LinePosition;
}
}
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);
{
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;
}
reader.MoveToElement();
_curNsAttr = index;
_nsIncReadOffset = 0;
- SetCurrentNode(_nsAttributes![index]!);
+ SetCurrentNode(_nsAttributes![index]);
}
private bool InitReadElementContentAsBinary(State binaryState)
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);
}
else
{
SetupFromParserContext(context, settings);
- Debug.Assert(_nameTable != null);
nt = _nameTable;
}
}
// 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);
else
{
Throw(SR.Xml_UnknownNs, node.prefix, node.LineNo, node.LinePos);
- return null!;
+ return null;
}
}
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 });
}
}
}
else
{
- IDtdDefaultAttributeInfo? attrDef = x as IDtdDefaultAttributeInfo;
- if (attrDef != null)
+ if (x is IDtdDefaultAttributeInfo attrDef)
{
localName = attrDef.LocalName;
prefix = attrDef.Prefix;
}
else
{
- IDtdDefaultAttributeInfo? attrDef = y as IDtdDefaultAttributeInfo;
- if (attrDef != null)
+ if (y is IDtdDefaultAttributeInfo attrDef)
{
localName2 = attrDef.LocalName;
prefix2 = attrDef.Prefix;
// 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();
}
}
// 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);
}
// 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);
}
// 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);
}
// 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)
{
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)
{
using System.Collections;
using System.Diagnostics;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
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)
{
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)