Search code examples
c#.netreflection

How do I get a list of all loaded Types in C#?


I need to retrieve all enums that were loaded from a given set of Assemblies.


Solution

  • 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 ;-)