Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Fluent Validator缺少SetCollectionValidator()方法_C#_Validation_Fluentvalidation - Fatal编程技术网

C# Fluent Validator缺少SetCollectionValidator()方法

C# Fluent Validator缺少SetCollectionValidator()方法,c#,validation,fluentvalidation,C#,Validation,Fluentvalidation,我是新来的流畅验证,昨天刚从nu Get获得版本5.3。我正在尝试将现有验证器(PhoneValidator)应用于类(Employee)的集合属性(ICollection)。Fluent Validator文档说明要使用: RuleFor(x => x.Orders).SetCollectionValidator(new OrderValidator()); // example usage 但是,SetCollectionValidator()方法在我的版本上不可用。相反,只有标记为

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

RuleFor(x => x.Orders).SetCollectionValidator(new OrderValidator()); // example usage
但是,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]$");            
    }
}
使用FluentValidation;
使用FluentValidation.validator;
公共类EmployeeValidator:AbstractValidator
{
公共雇员验证器()
{            
//SetCollectionValidator不会在intellisense中显示,也不会编译
RuleFor(e=>e.PhoneNumbers).SetCollectionValidator(新的PhoneValidator());
}
}
公共类PhoneValidator:AbstractValidator
{
公共电话验证器()
{
RuleFor(e=>e.Number).Length(10).Matches(“^[0-9]$”);
}
}

我来晚了,但这是谷歌的第一次成功,所以我认为这会帮助其他人。API似乎已更改,您现在需要执行以下操作:

RuleForEach(e=>e.PhoneNumbers).SetValidator(新的PhoneValidator());

在我看来更好一点。

您可以添加Employee类(或者至少添加Employee类中PhoneNumber属性的类型)吗