Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

RuleBuilderOptionsExtension.cs

using FluentValidation;

namespace Nop.Web.Framework.Validators;

public static class RuleBuilderOptionsExtension
{
    public static IRuleBuilderOptions WithMessageAwait(
        this IRuleBuilderOptions rule, Task errorMessage)
    {
        return rule.WithMessage(errorMessage.Result);
    }

    public static IRuleBuilderOptions WithMessageAwait(
        this IRuleBuilderOptions rule, Func> errorMessage)
    {
        return rule.WithMessage(errorMessage().Result);
    }

    public static IRuleBuilderOptions WithMessageAwait(
        this IRuleBuilderOptions rule, Task errorMessage, params object[] args)
    {
        return rule.WithMessage(string.Format(errorMessage.Result, args));
    }

    public static IRuleBuilderOptions MustAwait(this IRuleBuilder ruleBuilder,
        Func> predicate)
    {
        return ruleBuilder.Must((x, context) => predicate(x, context).Result);
    }

    public static IRuleBuilderOptions WhenAwait(this IRuleBuilderOptions rule,
        Func> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators)
    {
        return rule.When((x) => predicate(x).Result, applyConditionTo);
    }
}