Extending Validator or Validator<T>

Topics: Validation Application Block
Oct 13, 2010 at 2:15 AM

What is the difference between DoValidation and Validate...I see that DoValidate can be overidden....lets say I wanted to get the typical Validation and then do some extra validation of my own through code in my concrete implementation

Would this be the path I would want go down?:

public class MyValidator:Validator {

   private ValidationResults RunMyExtendedValidation(){
        ValidationResults  extendedValidationResults = new ValidationResults();
        // Do some validation here
        return extendedValidationResults;
    public override void  DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults){
        // Run the normal validation

        // Run any extended validation
        ValidationResults extendedResults = this.RunMyExtendedValidation();
        // Log the results
        base.LogValidationResult(extendedResults, "some validation message", objectToValidate,key);
Oct 13, 2010 at 3:07 AM

You would notice the difference in the type of the objectToValidate parameter.  You would inherit from Validator<T> if you want to create strongly-typed validators.  Otherwise, use the Validator class. 


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.