Reputation: 1
O've seen "get namespace from assembly" -- but how do you know what assembly the namespace is in? I'm trying to get all types of a namespace, and to do that I need to know the assembly, but the assembly isn't always just Assembly.GetExecutingAssembly, I need to get a list of all assemblies with a particular namespace in them.
How can I do this
Upvotes: 1
Views: 11898
Reputation: 471
You can't know beforehand what namespaces are defined in an assembly (not directly; in order to do that you need a decompiler and then a file parser to check their namespaces).
The thing you could do is load all the assemblies you want System.Reflection.Assembly Load(pathToAssembly)
and then go through their .DefinedTypes()
to filter the namespaces you want.
Loading all the assemblies for your current project:
List<Assembly> assemblies = new List<Assembly>();
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
foreach (var path in Directory.GetFiles(assemblyFolder, "*.dll"))
{
assemblies.Add(Assembly.LoadFrom(path));
}
Upvotes: 4