Apologies for reviving an old discussion but this is the top result on Google for this issue.
Would it be possible to achieve this by registering each base validator's rules with the current validator?
Amendment to RegisterBaseValidator method:
Would it be possible to achieve this by registering each base validator's rules with the current validator?
Amendment to RegisterBaseValidator method:
protected void RegisterBaseValidator<TBase>(IValidator<TBase> validator)
{
// Ensure that we've registered a compatible validator.
if (validator.CanValidateInstancesOfType(typeof(T)))
{
foreach (var validationRule in validator)
this.AddRule(validationRule);
}
else
{
throw new NotSupportedException(string.Format("Type {0} is not a base-class or interface implemented by {1}.", typeof(TBase).Name, typeof(T).Name));
}
}
I have tried this successfully with both client side and server side validation. Hopefully i'm not overlooking any other problems this may cause.