I implemented some extension methods and put them in a separate class library project.
Imagine I have a simple extension method like this in the MD.Utility class library :
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, for example, in the App_code folder or WebFroms code page, I can not use this extension method. If I like it:
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 = "Someone@Somewhere.com";
if (email.IsValidEmailAddress())
{
}
}
}
The compiler does not recognize IsValidEmailAddress () and does not even support intellisense.
Although if I put my extension method in the App_Code folder, then it’s normal for use in another cs file in the App_code Folder folders or in a web form.
source
share