简体   繁体   中英

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?

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.

I expected that you could to this with the EditorBrowsable attribute:

[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..

[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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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