Код: Выделить всё
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
< /code>
public class FooOfType
{
public string TypeName { get; set; }
public Foo Foo { get; set; }
}
< /code>
And these validators
public class FooValidator : AbstractValidator
{
public FooValidator()
{
RuleFor(f => f.Id).NotNull();
RuleSet("Name", () => {
RuleFor(f => f.Name).NotNull();
});
RuleSet("Email", () => {
RuleFor(f => f.Email).NotNull();
});
}
}
< /code>
public class FooOfTypeValidator : AbstractValidator
{
private string _fooType = "Name"; // default type
public FooOfTypeValidator()
{
RuleFor(f => f.TypeName)
.NotNull();
RuleFor(f => f.Foo).SetValidator(new FooValidator(), _fooType // can this be dynamic);
}
}
< /code>
If I run this validator _fooTypeон установлен в конструкторе.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... -rule-sets