Click here to Skip to main content
15,881,172 members
Articles / Web Development / ASP.NET

Creating Validation Engine for Domain Objects

Rate me:
Please Sign up or sign in to vote.
4.59/5 (11 votes)
15 Aug 2008CPOL3 min read 67K   397   45  
In this article we will build a simple domain object validation framework using custom attributes and reflection.
using System;
using System.Collections.Generic;
using System.Text;

namespace ValidationFramework.Library.CustomAttributes
{
    public class RequiredLengthAttribute : ValidationAttribute
    {
        private int _minLength;

        public RequiredLengthAttribute() { }

        public RequiredLengthAttribute(int minLength)
        {
            _minLength = minLength;
        }

        public override bool IsValid(object item)
        {
            if (((string)item).Length < _minLength)
                return false;

            return true;             
        }
    }
}

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 Code Project Open License (CPOL)


Written By
Web Developer
United States United States
My name is Mohammad Azam and I have been developing iOS applications since 2010. I have worked as a lead mobile developer for VALIC, AIG, Schlumberger, Baker Hughes, Blinds.com and The Home Depot. I have also published tons of my own apps to the App Store and even got featured by Apple for my app, Vegetable Tree. I highly recommend that you check out my portfolio. At present I am working as a lead instructor at DigitalCrafts.




I also have a lot of Udemy courses which you can check out at the following link:
Mohammad Azam Udemy Courses

Comments and Discussions