470,620 Members | 1,460 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,620 developers. It's quick & easy.

Sharing namespaces across projects?

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.

Nov 17 '05 #1
5 7954
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

<ge*****************@yahoo.co.uk> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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.

Nov 17 '05 #2
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.

"ge*****************@yahoo.co.uk" wrote:
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.

Nov 17 '05 #3
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.

Nov 17 '05 #4
Thanks Daniel. Pretty obvious really.
Not sure how I confused myself about that.

Nov 17 '05 #5
Sorry, I miss understood the question I guess. I missed the part about
wanting to get access to the internal methods not shared... :-)

glenn

<ge*****************@yahoo.co.uk> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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.

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by DKode | last post: by
1 post views Thread by Simon Neve | last post: by
reply views Thread by Darren Oakey | last post: by
2 posts views Thread by David | last post: by
2 posts views Thread by Jeff Dege | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.