C # extension methods in the "site.master" template, which is confined to the namespace quandary

The question is why do I need to add the "import" directive to my Site.Master file to get Intellisense when the html helpers work without it.

Using a simple C # string extension method without a namespace == is not a problem. However, I wanted this namespace extension to be a good programmer.

If I wrap it in a namespace , you need 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 work, but wanted to share my observations. Hope this can help someone else in the future.

. Site.Master

  • "using MySystemCore"; Site.Master.cs ( codebehind)

    • ,
  • "<add namespace="MySystemCore">" <namespaces> web.config

    • , intellisense
  • # 1 # 2

    • , intellisense
  • "<%@ Import Namespace="MySystemCore" %>" Site.Master

    • intellisense
+3
2

VS, , <namespaces> web.config, IntelliSense .

, , :

1 , ( ASP.NET) (.. ) 2 , using , . IntelliSense , , VS , web.config. 3 , 2. 1 , .cs, . 2 .cs. 4 , VS , , .
+2

, . . , .

0

All Articles