/// <summary>
 /// Creates a builder for specifying a set of rules used to determine if input is valid.
 /// </summary>
 /// <param name="argument">The argument.</param>
 /// <returns>The builder.</returns>
 public static IArgumentValidationBuilder Accepts(this CommandArgument argument)
 => new ValidationBuilder(argument);
 public ValidationContext Create(CommandArgument argument)
 => new ValidationContext(argument, _app, null);
Пример #3
0
 public ValidationResult GetValidationResult(CommandArgument argument, ValidationContext context)
 => GetValidationResult(argument.Values, context);
Пример #4
0
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
        /// <summary>
        /// Indicates the argument is required.
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <param name="allowEmptyStrings">Indicates whether an empty string is allowed.</param>
        /// <param name="errorMessage">The custom error message to display. See also: <see cref="ValidationAttribute.ErrorMessage"/>.</param>
        /// <returns>The argument.</returns>
        public static CommandArgument <T> IsRequired <T>(this CommandArgument <T> argument, bool allowEmptyStrings = false, string?errorMessage = null)
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters
        {
            IsRequired((CommandArgument)argument, allowEmptyStrings, errorMessage);
            return(argument);
        }
Пример #5
0
 /// <summary>
 /// Adds a validator that runs after parsing is complete and before command execution.
 /// </summary>
 /// <param name="argument">The argument.</param>
 /// <param name="validate">The callback. Return <see cref="ValidationResult.Success"/> if there is no error.</param>
 /// <returns></returns>
 public static CommandArgument OnValidate(this CommandArgument argument, Func <ValidationContext, ValidationResult> validate)
 {
     argument.Validators.Add(new DelegateValidator(validate));
     return(argument);
 }
Пример #6
0
 /// <summary>
 /// Creates a builder for specifying a set of rules used to determine if input is valid.
 /// </summary>
 /// <param name="argument">The argument.</param>
 /// <returns>The builder.</returns>
 public static IArgumentValidationBuilder <T> Accepts <T>(this CommandArgument <T> argument)
 => new ValidationBuilder <T>(argument);
Пример #7
0
 public static CommandArgument <T> IsRequired <T>(this CommandArgument <T> argument, bool allowEmptyStrings = false, string?errorMessage = null)
 {
     IsRequired((CommandArgument)argument, allowEmptyStrings, errorMessage);
     return(argument);
 }