Exemplo n.º 1
0
        /// <summary>
        /// Add an option to the command.
        /// </summary>
        /// <typeparam name="T">The type of the option.</typeparam>
        /// <param name="optionName">The name of the option.</param>
        /// <param name="shortOptionName">The short name of the options.</param>
        /// <param name="defineOption">An action to define command</param>
        /// <returns>The <see cref="CommandBuilder"/> to chain calls.</returns>
        public CommandBuilder AddOption <T>(string optionName, string shortOptionName,
                                            Action <OptionBuilder> defineOption)
        {
            var optionBuilder = new OptionBuilder(optionName, shortOptionName, typeof(T));

            (defineOption ?? (_ => { }))(optionBuilder);
            _optionsBuilders.Add(optionBuilder);
            return(this);
        }
 /// <summary>
 /// Add the required validation to the option.
 /// </summary>
 /// <param name="optionBuilder">The <see cref="OptionBuilder"/>.</param>
 /// <returns>The <see cref="OptionBuilder"/> to chain calls.</returns>
 public static OptionBuilder Required(this OptionBuilder optionBuilder)
 {
     return(optionBuilder.AddValidation <RequiredAttribute>());
 }
 /// <summary>
 /// Add a validation to the option.
 /// </summary>
 /// <typeparam name="TValidation">The type of the validation attribute.</typeparam>
 /// <param name="optionBuilder">The <see cref="OptionBuilder"/>.</param>
 /// <returns>The <see cref="OptionBuilder"/> to chain calls.</returns>
 public static OptionBuilder AddValidation <TValidation>(this OptionBuilder optionBuilder)
     where TValidation : ValidationAttribute, new()
 {
     optionBuilder.AddValidation(new TValidation());
     return(optionBuilder);
 }