コード例 #1
0
        /// <summary>
        /// Creates a new instance of <see cref="CommandLineArgsConfigurationProvider"/>
        /// </summary>
        public CommandLineArgsConfigurationProvider(CommandLineArgsConfigurationSource source)
        {
            _source = source.Clone();

            _indexedArgumentDefinitions = source.ArgumentDefinitions
                                          .Where(ArgumentDefinition.IsNamedForNamedArguments)
                                          .SelectMany(definition => ArgumentDefinition.GetAllNames(definition)
                                                      .CatMaybes()
                                                      .Select(name => (Key: name, Definition: definition)))
                                          .ToDictionary(p => p.Key, p => p.Definition, StringComparer.Ordinal); // index is case sensitive

            _valueDefinitions = source.ArgumentDefinitions
                                .OfType <ArgumentDefinition.RequiredValueDefinition>()
                                .Select(p => p.ConfigurationKey)
                                .ToList();
        }
コード例 #2
0
        /// <summary>
        /// Adds a command line configuration source to <paramref name="builder"/>.
        /// </summary>
        /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
        /// <param name="newSource">An instance of <see cref="CommandLineArgsConfigurationSource"/> that is used to provide an <see cref="CommandLineArgsConfigurationProvider"/></param>
        /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
        public static IConfigurationBuilder AddCommandLine(this IConfigurationBuilder builder, CommandLineArgsConfigurationSource newSource)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.Add(newSource));
        }