Using MEF in a Windows Store App: Listing 1

ValidateEmail class.

using System.Composition;
using System.Text.RegularExpressions;

namespace BusinessRules
{
    [Export(typeof(IValidate))]
    [ExportMetadata("Name", "Email")]
    public class ValidateEmail : IValidate
    {
        const string EMAIL_PATTERN = @"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$";

        public string Validate(string input)
        {
            if (Regex.IsMatch(input, EMAIL_PATTERN))
            {
                return "Email is valid.";
            }
            else
            {
                return "Email is not valid.";
            }
        }
    }
}

About the Author

Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at [email protected].

comments powered by Disqus

Featured

Subscribe on YouTube