在.NET全球导入/使用别名 [英] Global Import/using Aliasing in .NET

查看:159
本文介绍了在.NET全球导入/使用别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个文件/班采用进口走样,我们可以通过指定自己的自定义别名,像这样引用类库命名空间:

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.Lib.Data.Objects 

// C#
using Db = Company.Lib.Data.Objects;

然后我们可以使用 DB Company.Lib.Data.Objects 里面的类>别名,我们分配。

And then we are able to reference the classes inside of Company.Lib.Data.Objects by using the Db alias that we assigned.

是否有可能在全球范围内做到这一点,这样的别名应用到整个解决方案,而不是仅仅一个文件/类?

Is it possible to do this at the global level so that the alias is applied to the entire solution instead of just one file/class?

目前,我们正在与Web应用程序,所以我希望我们可以添加东西的web.config,但是我也有兴趣在这个是否可以使用Windows窗体,控制台应用程序,和/或类库。

Currently, we are working with web applications, so I was hoping we could add something to web.config, but I am also interested in whether or not this is possible with windows forms, console apps, and/or class libraries.

推荐答案

是的,这是在VB.Net项目支持的方案。要做到这一点的方法是以下

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

  • 右键单击Solution Explorer中的项目,然后选择属性
  • 转到参考标签
  • 在导入的命名空间字段中键入分贝= Company.Lib.Data.Objects
  • 点击添加用户导入

这将设置别名项目中的所有文件。

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

然而,这并不在C#项目工作。 C#作为一种语言没有一个全球性的使用/进口的概念。相反,它仅支持他们在文件级别。

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.

这篇关于在.NET全球导入/使用别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆