I have a method that was dooing some work on all the classes of an assembly :
var library = Assembly.LoadFrom(libraryPath);
IEnumerable<Type> types = library.GetTypes();
foreach (Type type in types)
{
[...]
}
The thing is that now, I’d like to split my code for each namespace of my assembly ! Something like
var library = Assembly.LoadFrom(libraryPath);
IEnumerable<Type> types = library.GetTypes();
foreach (/*namespace in my assembly*/)
{
foreach (Type type /*in my Namespace*/)
{
[...]
}
}
But after all my researches on the web and here on SO I didn’t find anything that I like…
The only thing I was able to do is :
List<string> namespaceList = new List<string>();
foreach (Type type in types)
{
if (!namespaceList.Contains(type.Namespace))
{
namespaceList.Add(type.Namespace);
}
}
But I can’t do anything with this List…
Yes, I can loop through all members on namespaceList and then loop on all types and test if they are (string comparaison) inside the current namespace, but I really feel like it’s not the way to go…
Any help would be really appreciated !
You can use the LINQ GroupBy method: