Exemplo n.º 1
0
        CheckAsync(object argument, CommandContext context, IServiceProvider provider)
        {
            var value   = (argument as string)?.Length ?? Convert.ToDouble(argument);
            var success = IsMinimumInclusive && !IsMaximumInclusive
                ? Minimum <= value && value < Maximum
                : !IsMinimumInclusive && IsMaximumInclusive
                    ? Minimum < value && value <= Maximum
                    : IsMinimumInclusive && IsMaximumInclusive
                        ? Minimum <= value && value <= Maximum
                        : Minimum < value && value < Maximum;
            var result = success
                ? CheckResult.Successful
                : CheckResult.Unsuccessful(
                $"The provided argument was outside of the range: {(IsMinimumInclusive ? '[' : '(')}{Minimum}, {Maximum}{(IsMaximumInclusive ? ']' : ')')}.");

#if NETCOREAPP
            return(result);
#else
            return(Task.FromResult(result));
#endif
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 public override ValueTask <CheckResult> CheckAsync(object argument, CommandContext context)
 => (argument as string).IndexOf(Value, StringComparison) != -1
         ? CheckResult.Successful
         : CheckResult.Unsuccessful(
     $"The provided argument must contain the {(StringComparison.IsCaseSensitive() ? "case-sensitive" : "case-insensitive")} value: {Value}.");
Exemplo n.º 3
0
 /// <summary>
 ///     Returns a failed <see cref="CheckResult"/> with the specified reason.
 /// </summary>
 /// <returns> A failed <see cref="CheckResult"/>. </returns>
 protected static CheckResult Failure(string reason)
 => CheckResult.Failed(reason);
Exemplo n.º 4
0
 /// <inheritdoc />
 public override ValueTask <CheckResult> CheckAsync(object argument, CommandContext context)
 => Regex.IsMatch(argument as string)
         ? CheckResult.Successful
         : CheckResult.Unsuccessful($"The provided argument must match the regex pattern: {Regex}.");