My first Extension Method!

I'm so happy.  It wrote my first extension method, following Scott Guthrie's example at http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx.  In all fairness, the code came from http://www.geekzilla.co.uk/View8AD536EF-BC0D-427F-9F15-3A1BC663848E.htm.  I just merged it with the "extension method" thang.  So, what does this do?  It adds an IsGuid method to the string object.
 public static class MildExtensions
{
    public static bool IsGuid(this string expression)
    {
        if (expression != null)
        {
            Regex guidRegEx = new Regex(@"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
            return guidRegEx.IsMatch(expression);
        }
        return false;
    }
}

Comments

Popular Posts