如何在派生类型的集合项上设置验证器?
class BaseClass
{
}
class DerivedClass : BaseClass
{
}
class SomeClass
{
public IEnumerable<BaseClass> BaseClasses { get; set; }
}
class DerivedClassValidator : AbstractValidator<DerivedClass>
{
}
class SomeClassValidator : AbstractValidator<SomeClass>
{
public SomeClassValidator()
{
RuleFor(x => x.BaseClasses).????.SetCollectionValidator(new DerivedClassValidator);
}
}
我在想...
有没有一种方法可以将它转换为特定类型,比如
RuleFor(x => x.SomeCollection).CastTo(typeof(SomeDerivedType)).SetCollectionValidator(new SomeDerivedValidator());