public class BaseValidator<T> : AbstractValidator<T> where T: Base
{
public BaseValidator()
{
RuleFor(data => data.Age).GreaterThan(18).WithMessage("The age must be greater than 18 years");
RuleFor(data => data.Name).NotEmpty().WithMessage("The name must not be empty");
}
}
public class ChildAValidator : BaseValidator<ChildA>
{
public ChildAValidator()
{
RuleFor(data => data.YeardOfExperience).GreaterThan(5).WithMessage("The years of experience must be greather than 5");
}
}
public class ChildBValidator : BaseValidator<ChildB>
{
public ChildBValidator()
{
RuleFor(data => data.Ratio).LessThanOrEqualTo(1).WithMessage("The ratio must be less or equal to 1");
}
}
↧
New Post: How to reuse validator for a base class?
↧