views:

296

answers:

4

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.

+1  A: 

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.

Jon Skeet
Hide the class - I don't need users to ever see the class name for the class that provides the methods - the methods however should function as usual (ie. be available against the appropriate supporting types in Intellisense) - does that make sense?
flesh
Sort of, but I don't think you're going to achieve it. Is it really a problem if they see the class? I can't remember whether intellisense shows where an extension method comes from, but if it does I'd be surprised (as a user) to see a classname which I couldn't otherwise see any trace of.
Jon Skeet
No it isn't a huge problem, but I'm providing the assembly as a utility and want it to be as user friendly as possible. I'm not worried about users seeing the supplying class name when using an extension method - rather I dont want them trying to do 'SupplyingClass obj = new ...'
flesh
If it's a static class (which it has to be to contain an extension method), they won't be able to do that anyway - the compiler will stop them. Make the class name indicate the use, e.g. "SupplyingClassExtensions" and then it should be obvious.
Jon Skeet
+1  A: 

I expected that you could to this with the EditorBrowsable attribute: [EditorBrowsable(EditorBrowsableState.Never)] static class MyExtensions { }

Unfortunately this did not seem to work.

Hallgrim
A: 

If you put your extension methods in a module there is a attribute called HideModuleName which will hide the module name from showing up in Intellisense.

Nathan W
+1  A: 

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.

flesh