May 2 2009

Internal Access Modifier on C# Namespaces

Category: C# | silverlight 2.0Bil@l @ 00:08

As part of a Silverlight applicatin I am currently developing, I have a small API that ships with the application that allows extending it with more features. I had few "Default" implementations inside the API and hence I placed them within a Namespace where all classes are marked as Internal.

Now, when I started working on the app, I created a Visual Studio Blank Solution. So the Silverlight application and the API are in the same blank empty solution inside VS 2008. When I access the main Namespace of the API, I always get to see the name of the default implementations, however as empty since all classes inside it are internal. 

So how can I hide the Namespace that contains all those implementations? I read this blog here "http://www.bartlannoeye.be/blog/2008/08/06/MakeCNamespaceInternal.aspx" which helped me do what I want, but I thought of illustrating a bit more here in this post to clarify the idea more.

Rule 1: Make sure all the classes inside the Namespace you want to hide are marked as Internal.

Rule 2: If you add a reference to a project whose source code is in the same solution, you will always see the Namespace name however empty with no classes.

Rule 3: If you add a reference to a project whose source code is not present in the current application, the Namespace name that contains all internal classes will be hidden.

 

I tried it out and seems to work very nice.

Hope this helps,
Regards

Tags: ,

Comments are closed