Dec 10, 2009 at 9:19 AM
Edited Dec 10, 2009 at 9:21 AM
I've just recently started exploring the Enterprise Library and now I'm looking at the Validation Application Block. I was thinking about using them to expose a method on my classes that returns if the object is currently valid or not (inspirated by the
Northwind Starter Kit).
However, I don't want to re-implement the code for this in every class so I have setup a base class (a test example below) that exposes the methods. At the same time I would like to enable subclasses to implement their custom validation that cannot
be expressed in attributes easily by just overriding a method, so I tried using the SelfValidation/HasSelfValidation attributes which worked perfectly in the subclass as long as I also decorated the subclasses with the HasSelfValidation attribute.
The problem with this approach is that it might be easy to forget adding this attribute to subclasses in the future, so I was wondering why this attribute (HasSelfValidation) isn't inherited to subclasses? What are the design reasons for this? The SelfValidation-attribute
is inherited, why isn't HasSelfValidation this as well?
Any insight is helpful! Thanks!
public class MyBaseClass
public virtual void CustomValidate(ValidationResults results)
public bool IsValid()
public ValidationResults Validate()
Validator validator = ValidationFactory.CreateValidator(this.GetType());