Geeks With Blogs
Jonathan Starr's Blog Thoughts on C#, Ajax, WCF, LINQ, Agile et al.

improve my => 'code'

I wrote some code in a test project, and then had to list all of the namespaces I used in my project for a manager so they could conform to a standard for production... As I used more than 50 namespaces for my test project, I wanted to do this automatically... Also I wanted to show all of the classes contained in each namespace...  Anyway, I used the following code... Thought this might be useful to others...  (If someone reading this sees a good way to refactor this, it would be appreciated!)

      Dictionary<string, List<string>> colNamespaces = new Dictionary<string, List<string>>();

      Assembly assembly = Assembly.GetAssembly( Type.GetType("Test2.Facade.ConcreteFacade,Test2"));

      Type[] theTypes = assembly.GetTypes();

      foreach ( Type t in theTypes)


            string theNameSpace = t.FullName.Substring(0,t.FullName.LastIndexOf("."));

            string theClass = t.FullName.Substring(t.FullName.LastIndexOf(".")+1);

            if (colNamespaces.ContainsKey(theNameSpace))






                List<string> classes = new List<string>();

                classes.Add( theClass );

                colNamespaces[theNameSpace] = classes;



I hope you find this helpful -

Jonathan Starr 

Posted on Monday, October 22, 2007 1:27 PM C# | Back to top

Comments on this post: Enumerating all of the namespaces and their respective classes in an assembly (dll).

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Jonathan Starr | Powered by: