Sharing namespaces across projects?

G

Guest

Is it valid to share namespaces across projects in C#?

For example, I have a project that contains the code for a core
assembly, this builds a DLL. I then have a second project in the same
solution that contains test cases for the assembly in the same
namespace, this references the first project's DLL and builds a further
DLL for testing. All code has the same namespace. The code in the tests
needs access to internal methods etc of the core assembly that wouldn't
be available outside the namespace.
 
G

glenn

Yes, this is doable... A namespace only gives you ways to seperate your
code from other developers in case of name conflicts within the source code.
If you are writing all the pieces and have no reason to use seperate
namespaces then you don't have to, however, you bring up something that I
think you might not fully understand.

Just because you place components into their own namespace doesn't mean that
you can't access them from other parts of the program that might use
different name spaces. It only means that you have to add a using statement
to tell your source that that unit uses another namespace as well.

Good luck,

glenn
 
G

Guest

internal is assembly scoped, not namespace scoped. so while you can spread a
namespace across multiple assemblies, it still won't solve your problem.
your unit test classes reside in a different assembly still can't access the
internal members of the core assembly.
 
G

Guest

Sorry Glen I don't understand the point you're making in your last
paragraph? If the methods are marked internal then they can't be used
outside the namespace even with a using clause.

The methods I am testing are marked internal so they won't be available
to other users, but I need access in my test cases and so my test cases
are in the same namespace - so should be able to access the internal
methods.
 
G

glenn

Sorry, I miss understood the question I guess. I missed the part about
wanting to get access to the internal methods not shared... :)

glenn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top