예제 #1
0
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters

        /// <summary>
        /// Constructor that requires an explicit implementation of
        /// <see cref="ILoopClient"/>.
        /// </summary>
        /// <param name="commandType">Type that defines syntax for commands.</param>
        /// <param name="loopClient">The client to use.</param>
        /// <param name="argSetAttribute">Optionally provides attribute info
        /// for the argument set that will be dynamically created for this loop.</param>
        /// <param name="options">Optionally provides additional options for
        /// this loop's execution.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="commandType" />
        /// is null.</exception>
        public Loop(Type commandType, ILoopClient loopClient, ArgumentSetAttribute argSetAttribute = null, LoopOptions options = null)
        {
            if (commandType == null)
            {
                throw new ArgumentNullException(nameof(commandType));
            }

            _client = loopClient ?? throw new ArgumentNullException(nameof(loopClient));
            _client.TokenCompleter = new TokenCompleter(this);

            _options = options?.DeepClone() ?? new LoopOptions();
            _options.ParserOptions.DisplayUsageInfoOnError = false;
            _options.ParserOptions.Reporter = error => _client.OnError(error.ToString().TrimEnd());

            var inputConfigurer = _options.ParserOptions.ServiceConfigurer;

            _options.ParserOptions.ServiceConfigurer = collection => ConfigureServices(collection, inputConfigurer);

            var constructedType = ConstructCommandTypeFactory(commandType, out _objectFactory);

            _argSet = AttributeBasedArgumentDefinitionFactory.CreateArgumentSet(
                constructedType,
                attribute: argSetAttribute,
                serviceConfigurer: _options.ParserOptions.ServiceConfigurer);
        }
예제 #2
0
 /// <summary>
 /// Constructor that creates a loop with a default client.
 /// </summary>
 /// <param name="commandType">Type that defines syntax for commands.</param>
 /// <param name="parameters">Optionally provides parameters controlling
 /// the loop's input and output behaviors; if not provided, default
 /// parameters are used.</param>
 /// <param name="argSetAttribute">Optionally provides attribute info
 /// for the argument set that will be dynamically created for this loop.</param>
 /// <param name="options">Optionally provides additional options for
 /// this loop's execution.</param>
 public Loop(Type commandType, LoopInputOutputParameters parameters = null, ArgumentSetAttribute argSetAttribute = null, LoopOptions options = null)
     : this(commandType, CreateClient(parameters ?? new LoopInputOutputParameters()), argSetAttribute, options)
 {
 }