【问题标题】:namespace being shadowed命名空间被遮蔽
【发布时间】:2012-02-16 22:08:46
【问题描述】:

所以我有一个库 Mine.SuperFun,它调用库 SuperFun 中的东西,其主命名空间是 SuperFun。我遇到的问题是我无法在 Mine.SuperFun.XyZFoo 命名空间中的类内的 SuperFun 库中处理类或基本上任何东西

解决这些问题的唯一方法是:

using SuperFun_NiceClass = SuperFun.NiceClass;

using Mine.SuperFun {

...

SuperFun_NiceClass.DoStuff()

我可以做些什么(除了更改 Mine 库中的命名空间)来直接处理这些类吗?

【问题讨论】:

  • 不,我不能完全限定它们.. 这就是问题
  • 很好的问题......我已经碰到过几次......并且只是做了你所做的。全球:: 不错!感谢 lurscher 发布这个问题。

标签: c# namespaces


【解决方案1】:

您可以使用global 上下文关键字

What is the usage of global:: keyword in C#?

http://msdn.microsoft.com/en-us/library/cc713620.aspx

namespace Mine.SuperFun
{
    public class My { public int a; }
}

namespace SuperFun
{
    public class Theirs { public int a; }
}

namespace SomeProgram
{
    public class Program
    {
        SuperFun.Theirs theirs;
        global::Mine.SuperFun.My mine;
    }
}

【讨论】:

    猜你喜欢
    • 2012-04-24
    • 1970-01-01
    • 2011-02-21
    • 2016-08-29
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    相关资源
    最近更新 更多