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))
{
colNamespaces[theNameSpace].Add(theClass);
}
else
{
List<string> classes = new List<string>();
classes.Add( theClass );
colNamespaces[theNameSpace] = classes;
}
}
I hope you find this helpful -
Jonathan Starr