tags:

views:

50

answers:

3

Can I have

namespace somenamespace
{
//references functionality in DLL_1
      namespace somesubnamespace
      {
       //references functionality in DLL_2
      }
}

And if I do this, when I use just somenamespace, will it only include DLL_1 in the solution and if I use somenamespace.somesubnamespace will it include DLL_1 and DLL_2 in the solution?

Or are DLL_1 and DLL_2 set on the project that contains the namespace and no matter which I use, both DLLs will be copied?

+1  A: 

If you add references to the DLLs, they will be copied. Since you must add the reference in order to use them, both will always be copied.

Oded
Wrong. You don't need to add a reference to an indirect dependency if you never use it.
SLaks
@Slaks - my understanding is that he is asking if using namespaces affects what DLLs are copied to the output directory.
Oded
+2  A: 

You only need to add references to the DLLs that your code actually uses (directly or indirectly).

Therefore, if library X has two classes that reference library A and B respectively, and you only use the class that references library A, you do not need library B at all.

Namespaces are organizational concepts and have nothing to do with it.

SLaks
+1  A: 

Your code above is exactly equivalent to:

namespace.somesubnamespace
{

}

If you write it your way, or if you write it this way, accessing somesubnamespace is done exactly the same way in your code.

Namespaces are essentially just labels to organize your code. Depending on what your code is accessing will dictate what references you need - but the answer to your question is "no", the references for namespace will not necessarily be required. namespace.somesubnamespace is an independent namespace in that regard.

womp