Click here to Skip to main content
15,880,796 members
Articles / Programming Languages / C#

Introduction to the Validation Application Block

Rate me:
Please Sign up or sign in to vote.
3.65/5 (19 votes)
8 Apr 2007CDDL8 min read 78.1K   203   73  
An introduction to the Validation Applicaiton Block and its usage.
using System;
using System.Collections.Generic;
using System.Text;

// Need these to make it work
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace BusinessObjects
{
    [HasSelfValidation]
    public class SelfValidateAddress
    {
        [SelfValidation]
        public void CheckState(ValidationResults results)
        {
            // Perform custom validation here

            ValidationResult result = new ValidationResult("State not correct", this, null, null, null);
            results.AddResult(result);
        }

        [SelfValidation]
        public void CheckZipCode(ValidationResults results)
        {
            // Perform custom validation here

            ValidationResult result = new ValidationResult("ZipCode does not match City", this, null, null, null);
            results.AddResult(result);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)



Comments and Discussions