I need to retrieve all enums that were loaded from a given set of Assemblies.
Use Type. GetType to get the Type objects from an assembly that is already loaded.
Reflection objects are used for obtaining type information at runtime. The classes that give access to the metadata of a running program are in the System. Reflection namespace. The System.
List, nested. A List can have elements of List type. This is a jagged list, similar in syntax to a jagged array. Lists are not by default multidimensional in C#.
Here is a more functional solution:
AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(a => a.GetTypes())
.Where(t => t.IsEnum)
List<Type> list = new List<Type>();
foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type t in ass.GetExportedTypes())
{
if (t.IsEnum)
{
list.Add(t);
}
}
}
That should do, for all assemblies loaded by the current Appdomain, to get just from defined assemblies, just adjust ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With