Sometimes, you want to do some simple validation. For example, data should not exceed the reserved storage size for the field in the database.

image

In this example CustomerName must be less than 10 characters. So, the client code should look like this:

The customer name is filled with input from a textbox. The complete customer object is validated using a validation facade. Finally, a list box is populated with the validation results.

Use of a facade simplifies use of validation in the client. The facade itself looks like this:

But wait! This looks exactly like the Validation Application Block. That’s a coincidence!

Indeed. Since the callings are similar you easily can replace the plumbing with the real stuff later on if you want.

But be aware that there is a small difference. This simplified version does not use attributes, but self validation by implementing an ISelfValidation interface.

The object in question implements ISelfValidation as follows:

This way simple validation becomes very easy. So, kids please do try this at home.

Download(s) : [Download not found]