FluentValidation Call RuleSet and Common Rules

前端 未结 5 796
无人共我
无人共我 2021-02-08 04:24

I have the following class

public class ValidProjectHeader : AbstractValidator
    {
        public ValidProjectHeader()
        {         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-08 04:42

    Instead you could do this:

    using FluentValidation;
    ...
    FluentValidation.Results.ValidationResult resultCommon =
        validator.Validate(parameter, ruleSet: "default, Insert");
    

    The using directive is required to bring the Validate() extension method from DefaultValidatorExtensions into scope, which has the ruleSet property. Otherwise you will only have the Validate() method available from inheriting AbstractValidator, which doesn't have a ruleSet argument.

提交回复
热议问题