/// <summary> /// This overload allows applying rules based on actual object type, rather than matched interface. This is /// needed for validating extensions. /// </summary> private void Validate(object item, Type type) { if (item == null) { return; // Required fields should be checked by higher level objects } var rules = _ruleSet.Where(r => r.ElementType == type); foreach (var rule in rules) { rule.Evaluate(this as IValidationContext, item); } }
private void Validate <T>(T item) { if (item == null) { return; // Required fields should be checked by higher level objects } var rules = _ruleSet.Where(r => r.ElementType == typeof(T)); foreach (var rule in rules) { rule.Evaluate(_context, item); } }