Fluent Validator missing SetCollectionValidator () method

I am new to Fluent Validation and just got version 5.3 from nu Get it yesterday. I am trying to apply an existing validator (PhoneValidator) to a collection property (ICollection) of a class (Employee). The Fluent Validator documentation says:

RuleFor(x => x.Orders).SetCollectionValidator(new OrderValidator()); // example usage

However, the SetCollectionValidator () method is not available in the version I have. Instead, there is only SetValidator () , which is marked as [deprecated] . I saw other posts regarding the same situation and found out that SetCollectionValidator () is an extension method and must be sure that FluentValidation is imported. I do.

What am I missing here?

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]$");            
    }
}
+4
1

, Google, , . , API , :

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

, .

+8

Source: https://habr.com/ru/post/1542565/


All Articles