Fluent Validator缺少SetCollectionValidator()方法

raz*_*444 5 c# validation fluentvalidation

我是Fluent Validation的新手,刚刚从nu Get 获得了5.3版本.我正在尝试将现有验证器(PhoneValidator)应用于类(Employee)的集合属性(ICollection).Fluent Validator文档说要使用:

RuleFor(x => x.Orders).SetCollectionValidator(new OrderValidator()); // example usage
Run Code Online (Sandbox Code Playgroud)

但是,我的版本上没有SetCollectionValidator()方法.相反,只有SetValidator()被标记为[已弃用].我已经看到有关同样情况的其他帖子,并了解到SetCollectionValidator()是一个扩展方法,需要确保我已导入FluentValidation.我做.

我在这里错过了什么?

using FluentValidation;
using FluentValidation.Validators;

public class EmployeeValidator : AbstractValidator<Employee>
{
    public EmployeeValidator()
    {            
        // SetCollectionValidator doesn't show in intellisense and won't compile
        RuleFor(e => e.PhoneNumbers).SetCollectionValidator(new PhoneValidator()); 
    }
}

public class PhoneValidator : AbstractValidator<Phone>
{
    public PhoneValidator()
    {
        RuleFor(e => e.Number).Length(10).Matches("^[0-9]$");            
    }
}
Run Code Online (Sandbox Code Playgroud)

eth*_*th0 11

我迟到了,但这是谷歌的第一次打击所以我认为它会帮助别人.似乎API已经改变,你现在需要做:

RuleForEach(e => e.PhoneNumbers).SetValidator(new PhoneValidator());

在我看来更好一点.