Reasons for [HasSelfValidation] not inherited?

Topics: Validation Application Block
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()
			return Validate().IsValid;

		public ValidationResults Validate()
			Validator validator = ValidationFactory.CreateValidator(this.GetType());
			return validator.Validate(this);

Dec 10, 2009 at 9:37 AM


We'll ask the ent lib team regarding this and get back to you.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.