隐藏类库中仅包含内部类型的名称空间? [英] Hiding namespaces containing only internal types in a class library?

查看:76
本文介绍了隐藏类库中仅包含内部类型的名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类库,它具有几个仅包含内部类型的命名空间.

I have a class library that has a couple of namespaces containing only internal types.

但是,在应用程序项目中使用类库时,名称空间以智能感知显示,但是它们当然是空的.在其他项目中使用智能感知时,有什么办法让我完全隐藏名称空间?

However, when using the class library in an application project, the namespaces shows up in intellisense, but of course they are empty. Is there any way for me to hide the namespaces completely when using intellisense in other projects?

我也尝试将EditorBrowsableAttribute应用于所有内部类,但是我想做的就是将其应用于名称空间,这当然是不可能的.

I've tried to apply EditorBrowsableAttribute to all the internal classes as well, but what I'd like to do would be to apply that to the namespace, which is of course impossible.

或者是,如果我对此足够在意,我唯一的选择就是将类型移动到包含公共类型的名称空间中?

Or is, if I care enough about this, the only option I have to just move the types into a namespace that contains public types?

推荐答案

这取决于您如何引用类库:

It depends on how you're referencing your class library:

  • 如果您的解决方案中包含类库项目并使用项目引用,则始终会通过Intellisense看到该空名称空间.
  • 如果您引用的是类库的已编译dll,则只要它仅包含内部成员,您就不会在智能感知中看到命名空间的出现.

尝试一下:

namespace ClassLibrary1
{
    namespace Internal
    {
        internal class InternalClass
        {
            public int internalStuff { get; set; }
        }
    }

    namespace Public
    {
        public class PublicClass
        {
            public int publicStuff { get; set; }
        }
    }
}

如果通过项目引用进行引用,则会看到空的名称空间.如果您引用其中的dll,则不会.

If you reference this via a project reference, you'll see the empty namespace. If you reference a dll of it, you won't.

这篇关于隐藏类库中仅包含内部类型的名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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