简体   繁体   English

如何防止提供扩展方法的公共类出现在Intellisense中?

[英]How can I prevent a public class that provides extension methods from appearing in Intellisense?

Is there any way to 'hide' the name of a class, whose sole purpose is to provide extension methods, from Intellisense? 有没有办法“隐藏”一个类的名称,其唯一目的是提供Intellisense的扩展方法?

I would like to remove the class name from the Intellisense list but need the extension methods of the class to be available to external assemblies via Intellisense in the usual way. 我想从Intellisense列表中删除类名,但需要通过Intellisense以通常的方式将类的扩展方法用于外部程序集。

I expected that you could to this with the EditorBrowsable attribute: 我希望您可以使用EditorBrowsable属性:

[EditorBrowsable(EditorBrowsableState.Never)]
static class MyExtensions { }

Unfortunately this did not seem to work. 不幸的是,这似乎不起作用。

Ok, I have the answer to this. 好的,我有答案。 Hallgrim's suggestion of marking the class with.. Hallgrim建议用......标记课程

[EditorBrowsable(EditorBrowsableState.Never)]

..does actually work but only where the assembly is being referenced, rather than the project, as would be the case in my own VS solution whilst writing the assembly that provides the class. ..实际上是工作但只是在引用程序集的地方,而不是项目,就像在我自己​​的VS解决方案中编写提供类的程序集一样。 The extension methods are available as usual. 扩展方法照常提供。

Do you mean you want to hide the class, or the extension methods? 你的意思是你想要隐藏类或扩展方法吗?

If you put the static class in its own namespace, then any code which doesn't import that namespace with a using directive won't "see" the extension methods. 如果将静态类放在它自己的命名空间中,那么任何不使用using指令导入该命名空间的代码都不会“看到”扩展方法。

如果将扩展方法放在模块中,则会有一个名为HideModuleName的属性,该属性将隐藏模块名称以显示在Intellisense中。

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

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