Possible to alias .NET namespaces in app.config?

前端 未结 1 1114
执笔经年
执笔经年 2021-01-17 20:16

ASP.NET has a feature that allows you to declare implicitly used namespaces in the web.config.


 
  
   &         


        
相关标签:
1条回答
  • 2021-01-17 20:40

    No. Namespaces are required at compile time. It's only scenarios where the compilation is done "late" (as in ASP.NET) where this makes any sense.

    What would it even mean to add a namespace at execution time, if the code has already been compiled?

    Are you really just after the option to avoid writing a bunch of using directives at the top of each file? If so, and if C# supported it, that would be in the project properties (which are about compilation, not execution). However, C# doesn't support that - the only imported namespaces are the ones specified by using directives in the current file.

    I think VB has the idea of "default namespaces" but C# definitely doesn't. Personally I think that's a good thing. (You might also want to look at this question. I don't know whether it's effectively a duplicate or not, as your intention isn't clear at the moment.)

    0 讨论(0)
提交回复
热议问题