tags:

views:

106

answers:

1

In java is easy to "hide" classes from outside your package(namespace), as you can define them as package-protected. There seems to be no equivalent keyword modifier in C#. Is there any way I could mimic that behaviour in C#? I have a couple of classes that I really wouldn't like the rest of the assembly to know of. It is ok for classes in the same namespace to know of, but I'd like them to be hidden from the rest of the library/application.

I know of the internal keyword, but that only hiddes classes if you try to access them from outside your assembly. That is not really my case, as I'd like to keep everything glued in just one .DLL/.EXE.

Thanks

+1  A: 

The only way I could think of achieving this is to put the classes that you want to be "package" private into a separate assembly along with the classes that use those that you do want exposed. Mark the classes in question as internal, and they are only visible to those parts of the project that really need it.

Considering the fact that you require this within one assembly I would tend to think that the assembly does too much and such refactoring could be beneficial.

Igor Zevaka
The assembly doesn't do too much. It's a pretty small assembly, but I'd like to hide a lot of "implementation" classes to the external namespaces. Isn't there a way to have different assemblies in the same .dll, through Visual Studio?
devoured elysium
adrianbanks
Hmm that seems useful. Nonetheless seems to much work for something so simple as this :(
devoured elysium