Saturday, May 22, 2010

[C#] How do I get the name of the current program's namespace as a string?

In C#, how do I get the name of the current program's namespace as a string?

[C#] How do I get the name of the current program's namespace as a string?
Hello,





Okay, now the question is a understandable. :) You have to recall that an application may or may not have an namespace, it is optional, but it is best to use it for organization and many other stuff that I explained in your other post.





Now to get the name of the program's namespace, I would assume your "current program" means the entry point of the program, therefore you will use Reflection to grab the namespace programatically. To do this you will need the following:





Make sure you remove the spaces (Yahoo formats it bad)


==========


string currentNamespace = Assembly . GetEntryAssembly() . GetTypes() [0] . Namespace;


==========





The above will grab the namespace defined in the Assembly. If your application has more than one namespace, then that assembly will be more than one arraysize.





Good Luck
Reply:// string //


No comments:

Post a Comment