diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/ref/Microsoft.Extensions.Configuration.CommandLine.cs b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/ref/Microsoft.Extensions.Configuration.CommandLine.cs index 0e629f4f11569..b1d4b8e21e383 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/ref/Microsoft.Extensions.Configuration.CommandLine.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/ref/Microsoft.Extensions.Configuration.CommandLine.cs @@ -8,16 +8,16 @@ namespace Microsoft.Extensions.Configuration { public static partial class CommandLineConfigurationExtensions { - public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCommandLine(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, System.Action configureSource) { throw null; } + public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCommandLine(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, System.Action? configureSource) { throw null; } public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCommandLine(this Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder, string[] args) { throw null; } - public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCommandLine(this Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder, string[] args, System.Collections.Generic.IDictionary switchMappings) { throw null; } + public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCommandLine(this Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder, string[] args, System.Collections.Generic.IDictionary? switchMappings) { throw null; } } } namespace Microsoft.Extensions.Configuration.CommandLine { public partial class CommandLineConfigurationProvider : Microsoft.Extensions.Configuration.ConfigurationProvider { - public CommandLineConfigurationProvider(System.Collections.Generic.IEnumerable args, System.Collections.Generic.IDictionary switchMappings = null) { } + public CommandLineConfigurationProvider(System.Collections.Generic.IEnumerable args, System.Collections.Generic.IDictionary? switchMappings = null) { } protected System.Collections.Generic.IEnumerable Args { get { throw null; } } public override void Load() { } } @@ -25,7 +25,7 @@ public partial class CommandLineConfigurationSource : Microsoft.Extensions.Confi { public CommandLineConfigurationSource() { } public System.Collections.Generic.IEnumerable Args { get { throw null; } set { } } - public System.Collections.Generic.IDictionary SwitchMappings { get { throw null; } set { } } + public System.Collections.Generic.IDictionary? SwitchMappings { get { throw null; } set { } } public Microsoft.Extensions.Configuration.IConfigurationProvider Build(Microsoft.Extensions.Configuration.IConfigurationBuilder builder) { throw null; } } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/ref/Microsoft.Extensions.Configuration.CommandLine.csproj b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/ref/Microsoft.Extensions.Configuration.CommandLine.csproj index e4886f5e0b697..5be8641b37613 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/ref/Microsoft.Extensions.Configuration.CommandLine.csproj +++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/ref/Microsoft.Extensions.Configuration.CommandLine.csproj @@ -1,10 +1,20 @@ - netstandard2.0;$(NetFrameworkMinimum) + $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) + enable + + + + + + + + + diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationExtensions.cs b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationExtensions.cs index c5e7ee43326fb..b39998e4d91d7 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationExtensions.cs @@ -152,7 +152,7 @@ public static IConfigurationBuilder AddCommandLine(this IConfigurationBuilder co public static IConfigurationBuilder AddCommandLine( this IConfigurationBuilder configurationBuilder, string[] args, - IDictionary switchMappings) + IDictionary? switchMappings) { configurationBuilder.Add(new CommandLineConfigurationSource { Args = args, SwitchMappings = switchMappings }); return configurationBuilder; @@ -164,7 +164,7 @@ public static IConfigurationBuilder AddCommandLine( /// The to add to. /// Configures the source. /// The . - public static IConfigurationBuilder AddCommandLine(this IConfigurationBuilder builder, Action configureSource) + public static IConfigurationBuilder AddCommandLine(this IConfigurationBuilder builder, Action? configureSource) => builder.Add(configureSource); } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs index fb1b17a521630..a41d6f541d02f 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs @@ -11,14 +11,14 @@ namespace Microsoft.Extensions.Configuration.CommandLine /// public class CommandLineConfigurationProvider : ConfigurationProvider { - private readonly Dictionary _switchMappings; + private readonly Dictionary? _switchMappings; /// /// Initializes a new instance. /// /// The command line args. /// The switch mappings. - public CommandLineConfigurationProvider(IEnumerable args, IDictionary switchMappings = null) + public CommandLineConfigurationProvider(IEnumerable args, IDictionary? switchMappings = null) { Args = args ?? throw new ArgumentNullException(nameof(args)); @@ -38,7 +38,7 @@ public CommandLineConfigurationProvider(IEnumerable args, IDictionary public override void Load() { - var data = new Dictionary(StringComparer.OrdinalIgnoreCase); + var data = new Dictionary(StringComparer.OrdinalIgnoreCase); string key, value; using (IEnumerator enumerator = Args.GetEnumerator()) @@ -68,7 +68,7 @@ public override void Load() if (separator < 0) { - // If there is neither equal sign nor prefix in current arugment, it is an invalid format + // If there is neither equal sign nor prefix in current argument, it is an invalid format if (keyStartIndex == 0) { // Ignore invalid formats @@ -76,7 +76,7 @@ public override void Load() } // If the switch is a key in given switch mappings, interpret it - if (_switchMappings != null && _switchMappings.TryGetValue(currentArg, out string mappedKey)) + if (_switchMappings != null && _switchMappings.TryGetValue(currentArg, out string? mappedKey)) { key = mappedKey; } @@ -105,7 +105,7 @@ public override void Load() string keySegment = currentArg.Substring(0, separator); // If the switch is a key in given switch mappings, interpret it - if (_switchMappings != null && _switchMappings.TryGetValue(keySegment, out string mappedKeySegment)) + if (_switchMappings != null && _switchMappings.TryGetValue(keySegment, out string? mappedKeySegment)) { key = mappedKeySegment; } diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationSource.cs b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationSource.cs index 36a665e360a48..1dc7ad911811c 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationSource.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationSource.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections.Generic; namespace Microsoft.Extensions.Configuration.CommandLine @@ -13,12 +14,12 @@ public class CommandLineConfigurationSource : IConfigurationSource /// /// Gets or sets the switch mappings. /// - public IDictionary SwitchMappings { get; set; } + public IDictionary? SwitchMappings { get; set; } /// /// Gets or sets the command line args. /// - public IEnumerable Args { get; set; } + public IEnumerable Args { get; set; } = Array.Empty(); /// /// Builds the for this source. diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj index 8a5598960f20e..bf8e1cce4abb2 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj +++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj @@ -1,8 +1,11 @@ - netstandard2.0;$(NetFrameworkMinimum) + $(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) + enable true + + false Command line configuration provider implementation for Microsoft.Extensions.Configuration.