Global Import/using Aliasing in .NET

前端 未结 2 1350
鱼传尺愫
鱼传尺愫 2020-12-11 02:46

Using import aliasing in one file/class, we can reference class library namespaces by assigning our own custom alias like this:

\' VB
Imports Db = Company.Li         


        
2条回答
  •  孤城傲影
    2020-12-11 03:48

    Yes this is a supported scenario in VB.Net projects. The way to do this is the following

    • Right Click on the project in Solution Explorer and select Properties
    • Go to the References tab
    • In the "Imported Namespaces" field type "Db=Company.Lib.Data.Objects"
    • Hit "Add User Import"

    This will set up the alias for all files in the project.

    This however does not work in C# projects. C# as a language doesn't have the concept of a global using/import. Instead it only supports them at the file level.

提交回复
热议问题