Friday, November 25, 2005

Suggestion: Validation Framework

I once had a need to mimic the functionality in the validation control framework – I had to validate values coming off of the querystring in asp.net. I initially thought of reusing part of the existing validation framework but after playing around and researching it a bit I realized that the framework is built on and too tightly coupled with the web form controls structure.

That got me thinking that you are limiting a very useful and powerful piece of functionality to one small piece of the .net framework.

There are many situations where a developer would need to validate values (not necessarily input) and once you have the basic structure – why not extend it.

Here is a suggestion that I had.

Rebuild the entire validation structure totally separated from the web control process. You can have web validation controls implement this feature – however so can others.

For example a programmer would be able to do something like this

If (Validator.Range(someInt,20,300))
{
// good
}
Else
{
//Bad
}

Or this would be great for parsing data types before you try to run a convert. (although the new TryPArse does help)

However I think one of the most interesting features can be from settting up a attribute system. A developer would be able to write something like this

[RangeValidated(30,100)]

Int I;

If a value out of range is assigned to I then a exception gets thrown (this can be thought of as built in Unit Testing)

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?