Extension methods in class library project

Posted by Mostafa on Stack Overflow See other posts from Stack Overflow or by Mostafa
Published on 2010-04-18T15:55:12Z Indexed on 2010/04/18 16:03 UTC
Read the original article Hit count: 405

I've implemented some extension methods and put those in separate Class Library project.

Imagine I have a simple extension method like this in class library called MD.Utility:

namespace MD.Utility
{
    public static class ExtenMethods
    {
        public static bool IsValidEmailAddress(this string s)
        {
            Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
            return regex.IsMatch(s);
        }
    } 
}

But nowhere in WebApp like App_code folder or WebFroms code-behind page I can't use this Extension method. If I do like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MD.Utility;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string email = "[email protected]";
        if (email.IsValidEmailAddress())
        {
            //To do 
        }
    }
}

The compiler doesn't recognize IsValidEmailAddress() and even no intellisense support.

While if I put my extension method in App_Code folder it's ok for using in another cs file in App_code Folder or Web Form code-behind pages.

© Stack Overflow or respective owner

Related posts about extension-methods

Related posts about class-library