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)
Add "<add namespace="MySystemCore">" to <namespaces> configuration block in web.config
Combine #1 and #2
Add "<%@ Import Namespace="MySystemCore" %>" to Site.Master file
It's a VS limitation that when you add it to <namespaces> in web.config, IntelliSense doesn't show up.
But for the sake of completeness, I'll discuss the cause of it:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With