Repository navigation
API Overview
Namespace: MarcusMedinaPro.ClassEnumerator
Note: the NuGet package is
MarcusMedina.Reflection.ClassEnumerator; the namespace has always stayedMarcusMedinaPro.ClassEnumerator, unchanged since the oldMMPClassEnumeratorpackage.
Generic static class. T is the interface or base class to search for.
IEnumerable<T> GetClassesByInterface(bool useCache = false, Assembly? assembly = null)Returns instances of all non-abstract classes in the assembly that implement T (where T is an interface).
- Results are sorted by type name.
- Classes must have a public parameterless constructor.
IEnumerable<T> GetClassesByInheritance(bool useCache = false, Assembly? assembly = null)Returns instances of all non-abstract classes whose direct base class is T.
- Results are sorted by type name.
- Classes must have a public parameterless constructor.
IEnumerable<Type> ListClassesByInterface(bool useCache = false, Assembly? assembly = null)Like GetClassesByInterface but returns Type objects instead of instances.
Useful when you need to inspect types without instantiating them.
IEnumerable<Type> ListClassesByInheritance(bool useCache = false, Assembly? assembly = null)Like GetClassesByInheritance but returns Type objects.
void ClearCache()Clears all cached results for every generic instantiation of EnumerateClasses<T>. Useful if assemblies are loaded dynamically at runtime and a previously cached scan is now stale.
| Parameter | Default | Description |
|---|---|---|
useCache |
false |
Cache results per assembly — faster on repeated calls |
assembly |
null |
Target assembly. Null = calling assembly |
Without cache, reflection scans all types on every call. Enable useCache: true in hot paths or for plugins discovered at startup. Call ClearCache() if you load assemblies dynamically after the first scan.