Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding namespaces containing only internal types in a class library?

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?

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?

like image 298
Lasse V. Karlsen Avatar asked Apr 06 '09 08:04

Lasse V. Karlsen


People also ask

How do I hide my namespace?

You can refrain from displaying the namespace of your node names so that they appear shorter. Disable Display > Show Namespace so that the namespaces do not appear with your node names. For example, Namespace1:pConeShape1 becomes ...:pConeShape1.

Are namespaces the same as libraries?

Namespaces provide a notional separation for classes, class libraries provide a physical separation (in windows think a standalone dll). Class libraries are useful for when you want to wrap up functionality that can be shared with other projects.


2 Answers

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

  • If you have the class library project contained within your solution and use a project reference, you'll always see that empty namespace via Intellisense.
  • If you're referencing a compiled dll of your class library, you won't see the namespace popping up in intellisense, provided it contains only internal members.

Try this:

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

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

like image 117
takrl Avatar answered Oct 06 '22 00:10

takrl


I've come up against this before and found no solution, only a workaround which may or may not work in your project. Instead of defining a namespace you could use an nested static class?

like image 27
James L Avatar answered Oct 06 '22 02:10

James L