This worked for me; I know this is slightly off topic but could someone help me with this ?
I have an abstract class which inherits from AbstractValidator thus :
```
public abstract class BaseValidator<T> : AbstractValidator<T>, IBaseValidator<T> where T : class, new()
{
public ValidationResult ValidateAll(T instance)
{
return this.Validate(instance, ruleSet: "*");
}
public ValidationResult Validate(T instance, params string[] ruleSets)
{
return ruleSets == null ? Validate(instance) : Validate(new ValidationContext<T>(instance, new PropertyChain(), new RulesetValidatorSelector(ruleSets)));
}
public ValidationResult Validate<TValue>(Expression<Func<T, object>> propertyExpression, TValue value)
{
return Validate(new T(), propertyExpression, value);
}
public ValidationResult Validate<TValue>(T instance, Expression<Func<T, object>> propertyExpression, TValue value)
{
MemberExpression memberExpr;
if (propertyExpression.Body is MemberExpression)
{
memberExpr = propertyExpression.Body as MemberExpression;
}
else if (propertyExpression.Body is UnaryExpression)
{
var unaryExpr = propertyExpression.Body as UnaryExpression;
memberExpr = unaryExpr.Operand as MemberExpression;
}
else
{
throw new ArgumentException();
}
if (memberExpr == null) throw new ArgumentException();
var propertyInfo = memberExpr.Member as PropertyInfo;
if (propertyInfo == null) throw new ArgumentException();
propertyInfo.SetValue(instance, value, null);
return this.Validate(instance, propertyExpression);
}
}
How could I extend the factory to server out my BaseValidator rather than the Abstract one ? Currently I have two factories - one for the ModelValidatorProvider in global.asax and another for my own BaseValidator that I use in the service layer.
Thanks