简体   繁体   English

C#-在全局命名空间中使用代码进行汇编

[英]C# - Assembly with code in global namespace

I am referencing an assembly in a project. 我正在引用项目中的程序集。 Is there a way to put everything in the assembly into a namespace? 有没有办法将程序集中的所有内容放入命名空间?

Right now everything in it is in the global namespace so it makes accessing things weird. 现在,其中的所有内容都位于全局命名空间中,因此访问内容很奇怪。

With help from the comment @PetSerAl made I found this page that helped a lot. 在评论的帮助下,@ PetSerAl使我发现此页面有很大帮助。 You can change what the alias is in the references properties and then in the file you want to use something from that assembly you put extern alias <alias> . 您可以在引用属性中更改别名的含义,然后在要使用该程序集中某些内容的文件中放入extern alias <alias>

Another way to accomplish this may be to use a namespace alias . 完成此操作的另一种方法可能是使用名称空间别名

Here is an example: 这是一个例子:

using nsAlias = System.Some.Long.Namespace;

namespace System
{
    class TestClass
    {
        static void Main()
        {
            // Using the alias:
            nsAlias.SomeObject test = new nsAlias.SomeObject();
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM