The question is this, why do I need to add an "import" directive on my Site.Master file to get Intellisense when the html helpers work without it.
Using a simple C# string extension method without a namespace == no problem. However, I wanted to put this extension in a namespace to be a good programmer.
If I wrap it in a namespace, you have to do a couple of things. Here is my extension:
namespace MySystemCore
{
public static class StringExtensions
{
public static string F(this string s, params object[] args)
{
return string.Format(s, args);
}
}
}
So through trial and error, I have it working, but wanted to share my observations. Hopefully it may help someone else in the future.
NOTE: I am using the extension method in Site.Master
Add "using MySystemCore;" to Site.Master.cs file (codebehind file)
- Runtime error, no extension method found
Add "
<add namespace="MySystemCore">
" to<namespaces>
configuration block in web.config- Works, no intellisense
Combine #1 and #2
- Works, no intellisense
Add "
<%@ Import Namespace="MySystemCore" %>
" to Site.Master file- Works, with intellisense