Skip to content

Commit

Permalink
[Group 5] Enable nullable annotations for `Microsoft.Extensions.Confi…
Browse files Browse the repository at this point in the history
…guration.Xml` (dotnet#67178)
  • Loading branch information
maxkoshevoi authored Apr 1, 2022
1 parent fc7da6e commit 063d080
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Microsoft.Extensions.Configuration
{
public static partial class XmlConfigurationExtensions
{
public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, Microsoft.Extensions.FileProviders.IFileProvider provider, string path, bool optional, bool reloadOnChange) { throw null; }
public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, System.Action<Microsoft.Extensions.Configuration.Xml.XmlConfigurationSource> configureSource) { throw null; }
public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, Microsoft.Extensions.FileProviders.IFileProvider? provider, string path, bool optional, bool reloadOnChange) { throw null; }
public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, System.Action<Microsoft.Extensions.Configuration.Xml.XmlConfigurationSource>? configureSource) { throw null; }
public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string path) { throw null; }
public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string path, bool optional) { throw null; }
public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string path, bool optional, bool reloadOnChange) { throw null; }
Expand All @@ -32,15 +32,15 @@ public partial class XmlDocumentDecryptor
{
public static readonly Microsoft.Extensions.Configuration.Xml.XmlDocumentDecryptor Instance;
protected XmlDocumentDecryptor() { }
public System.Xml.XmlReader CreateDecryptingXmlReader(System.IO.Stream input, System.Xml.XmlReaderSettings settings) { throw null; }
public System.Xml.XmlReader CreateDecryptingXmlReader(System.IO.Stream input, System.Xml.XmlReaderSettings? settings) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
protected virtual System.Xml.XmlReader DecryptDocumentAndCreateXmlReader(System.Xml.XmlDocument document) { throw null; }
}
public partial class XmlStreamConfigurationProvider : Microsoft.Extensions.Configuration.StreamConfigurationProvider
{
public XmlStreamConfigurationProvider(Microsoft.Extensions.Configuration.Xml.XmlStreamConfigurationSource source) : base (default(Microsoft.Extensions.Configuration.StreamConfigurationSource)) { }
public override void Load(System.IO.Stream stream) { }
public static System.Collections.Generic.IDictionary<string, string> Read(System.IO.Stream stream, Microsoft.Extensions.Configuration.Xml.XmlDocumentDecryptor decryptor) { throw null; }
public static System.Collections.Generic.IDictionary<string, string?> Read(System.IO.Stream stream, Microsoft.Extensions.Configuration.Xml.XmlDocumentDecryptor decryptor) { throw null; }
}
public partial class XmlStreamConfigurationSource : Microsoft.Extensions.Configuration.StreamConfigurationSource
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
<EnableDefaultItems>true</EnableDefaultItems>
<!-- Use targeting pack references instead of granular ones in the project file. -->
<DisableImplicitAssemblyReferences>false</DisableImplicitAssemblyReferences>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal sealed class XmlConfigurationElement
{
public string ElementName { get; }

public string Name { get; }
public string? Name { get; }

/// <summary>
/// A composition of ElementName and Name, that serves as the basis for detecting siblings
Expand All @@ -20,18 +20,18 @@ internal sealed class XmlConfigurationElement
/// <summary>
/// The children of this element
/// </summary>
public IDictionary<string, List<XmlConfigurationElement>> ChildrenBySiblingName { get; set; }
public IDictionary<string, List<XmlConfigurationElement>>? ChildrenBySiblingName { get; set; }

/// <summary>
/// Performance optimization: do not initialize a dictionary and a list for elements with a single child
/// </summary>
public XmlConfigurationElement SingleChild { get; set; }
public XmlConfigurationElement? SingleChild { get; set; }

public XmlConfigurationElementTextContent TextContent { get; set; }
public XmlConfigurationElementTextContent? TextContent { get; set; }

public List<XmlConfigurationElementAttributeValue> Attributes { get; set; }
public List<XmlConfigurationElementAttributeValue>? Attributes { get; set; }

public XmlConfigurationElement(string elementName!!, string name)
public XmlConfigurationElement(string elementName!!, string? name)
{
ElementName = elementName;
Name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builde
/// <param name="optional">Whether the file is optional.</param>
/// <param name="reloadOnChange">Whether the configuration should be reloaded if the file changes.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder!!, IFileProvider provider, string path, bool optional, bool reloadOnChange)
public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder!!, IFileProvider? provider, string path, bool optional, bool reloadOnChange)
{
if (string.IsNullOrEmpty(path))
{
Expand All @@ -85,7 +85,7 @@ public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builde
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="configureSource">Configures the source.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder, Action<XmlConfigurationSource> configureSource)
public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder, Action<XmlConfigurationSource>? configureSource)
=> builder.Add(configureSource);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class XmlDocumentDecryptor
/// </summary>
public static readonly XmlDocumentDecryptor Instance = new XmlDocumentDecryptor();

private readonly Func<XmlDocument, EncryptedXml> _encryptedXmlFactory;
private readonly Func<XmlDocument, EncryptedXml>? _encryptedXmlFactory;

/// <summary>
/// Initializes a XmlDocumentDecryptor.
Expand Down Expand Up @@ -50,7 +50,7 @@ private static bool ContainsEncryptedData(XmlDocument document)
/// <summary>
/// Returns an XmlReader that decrypts data transparently.
/// </summary>
public XmlReader CreateDecryptingXmlReader(Stream input, XmlReaderSettings settings)
public XmlReader CreateDecryptingXmlReader(Stream input, XmlReaderSettings? settings)
{
// XML-based configurations aren't really all that big, so we can buffer
// the whole thing in memory while we determine decryption operations.
Expand Down Expand Up @@ -98,7 +98,7 @@ protected virtual XmlReader DecryptDocumentAndCreateXmlReader(XmlDocument docume
// Finally, return the new XmlReader from the updated XmlDocument.
// Error messages based on this XmlReader won't show line numbers,
// but that's fine since we transformed the document anyway.
return document.CreateNavigator().ReadSubtree();
return document.CreateNavigator()!.ReadSubtree();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public XmlStreamConfigurationProvider(XmlStreamConfigurationSource source) : bas
/// <param name="stream">The stream of XML data.</param>
/// <param name="decryptor">The <see cref="XmlDocumentDecryptor"/> to use to decrypt.</param>
/// <returns>The <see cref="IDictionary{String, String}"/> which was read from the stream.</returns>
public static IDictionary<string, string> Read(Stream stream, XmlDocumentDecryptor decryptor)
public static IDictionary<string, string?> Read(Stream stream, XmlDocumentDecryptor decryptor)
{
var readerSettings = new XmlReaderSettings()
{
Expand All @@ -39,7 +39,7 @@ public static IDictionary<string, string> Read(Stream stream, XmlDocumentDecrypt
IgnoreWhitespace = true
};

XmlConfigurationElement root = null;
XmlConfigurationElement? root = null;

using (XmlReader reader = decryptor.CreateDecryptingXmlReader(stream, readerSettings))
{
Expand Down Expand Up @@ -211,7 +211,7 @@ private static void ReadAttributes(XmlReader reader, XmlConfigurationElement ele
throw new FormatException(SR.Format(SR.Error_NamespaceIsNotSupported, GetLineInfo(reader)));
}

element.Attributes.Add(new XmlConfigurationElementAttributeValue(reader.LocalName, reader.Value, lineNumber, linePosition));
element.Attributes!.Add(new XmlConfigurationElementAttributeValue(reader.LocalName, reader.Value, lineNumber, linePosition));
}

// Go back to the element containing the attributes we just processed
Expand All @@ -221,9 +221,9 @@ private static void ReadAttributes(XmlReader reader, XmlConfigurationElement ele
// The special attribute "Name" only contributes to prefix
// This method retrieves the Name of the element, if the attribute is present
// Unfortunately XmlReader.GetAttribute cannot be used, as it does not support looking for attributes in a case insensitive manner
private static string GetName(XmlReader reader)
private static string? GetName(XmlReader reader)
{
string name = null;
string? name = null;

while (reader.MoveToNextAttribute())
{
Expand All @@ -245,9 +245,9 @@ private static string GetName(XmlReader reader)
return name;
}

private static IDictionary<string, string> ProvideConfiguration(XmlConfigurationElement root)
private static IDictionary<string, string?> ProvideConfiguration(XmlConfigurationElement? root)
{
var configuration = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Dictionary<string, string?> configuration = new(StringComparer.OrdinalIgnoreCase);

if (root == null)
{
Expand Down

0 comments on commit 063d080

Please sign in to comment.