Click here to Skip to main content
15,886,723 members
Articles / Programming Languages / C#

Attribute-flavored Domain Driven Design

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
6 Apr 2008CPOL8 min read 39.1K   231   25  
A centralized business domain with a common base
using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Codebasement.DomainDrivenDesign.Basement.Utilities;

namespace Codebasement.DomainDrivenDesign.Model.Validators
{
    internal static class PropertyValidators
    {
        private const string caption = "Codebasement";

        internal static bool ValidateDateTime(string value)
        {
            try
            {
                DateTime.Parse(value);
            }
            catch
            {
                return false;
            }
            return true;
        }

        internal static object ValidateEnum(Type enumeration, string val, object deflt)
        {
            if (val != null && Enum.IsDefined(enumeration, val))
                return Enum.Parse(enumeration, val);
            return deflt;
        }

        internal static bool ValidateStringLength(string value, int min, int max)
        {
            if (value.Length < min ||
                value.Length > max)
            {
                MessageBox.Show(String.Format("Length must be between {0} and {1}.",min,max), 
                    caption,MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }

        internal static bool ValidateIPAddress(string value)
        {
            if (String.IsNullOrEmpty(value))
                return true;

            Regex regex = new Regex(RegexExpressions.IPAddressFormat);
            if (!regex.Match(value).Success)
            {
                MessageBox.Show("Not a valid IP address.", 
                    caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                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
Software Developer (Senior)
Netherlands Netherlands
Software engineer & architect.

Comments and Discussions