Extending and Modifying the Validation Application Block

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

In its original state, the Validation Application Block works well for typical validation scenarios, such as validating data for an ASP.NET application. However, there may be times when you have to customize certain behaviors of the application block to better suit your application's particular requirements. There are two ways to do this: extension and modification.

Extending the Validation Application Block

You extend the Validation Application Block through designated extension points. Typically, these are custom classes written by you that implement a particular interface or derive from an abstract class. Because these custom classes exist in your application space, you do not have to modify or rebuild the Validation Application Block; instead, you can designate your extensions through configuration settings.

You can extend the Validation Application Block by implementing new validators. To learn more, see Creating a New Validator.

Modifying the Validation Application Block

You modify the Validation Application Block by making changes to the Validation Application Block's source code. This may, or may not, require associated configuration changes. Because changes are made to the source code, you must rebuild the Validation Application Block before the modifications take effect. You must also be prepared to handle support and versioning issues. To learn more, see Modifying the Validation Application Block.

Creating a New Validator or Custom Attribute

You can create your own Validator classes and your own attributes if the ones provided with the Validation Application Block do not fit your requirements. These classes could validate data types in new ways or they could deal with more complex data types, such as a Customer data type that includes many different data types. For an example of a custom validator, see the DivisibleByValidator class in the Validation QuickStart.

To create your own attributes, create a class that derives from the ValidatorAttribute base class.

There are several approaches to creating your own validators. One approach is to create a class that inherits from the Validator<T> base class or from the Validator class. The first class is for strongly typed validators and the second is for loosely typed validators.

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.
Show: