Skip to content
Marcus Ackre Medina edited this page Sep 13, 2026 · 4 revisions

MarcusMedina.Reflection.ClassEnumerator

Discover and instantiate classes at runtime using reflection — by interface or by inheritance. Includes optional caching for performance.

dotnet add package MarcusMedina.Reflection.ClassEnumerator

Why this exists

This one came to be in 2022, while I was trying to explain to students how plugin systems actually work under the hood. Talking about "find every class that implements this interface" in the abstract wasn't landing — I needed something they could run and see immediately. It's maybe not the prettiest solution reflection has ever produced, but it did exactly what I needed: a simple way to list every class implementing a given interface.

In this case, I wanted the plugin-discovery idea to be something students could see working in five lines, not something buried in a framework they'd have to trust blindly.

Who this is for

  • New to reflection? See exactly how "find every class implementing X" works, in five lines, before you ever touch a full DI/plugin framework.
  • Professional? Lightweight class discovery for plugin architectures, dynamic module loading, or auto-registration into a DI container — with optional caching so repeated lookups don't cost you reflection overhead.

Pages

Quick Example

using MarcusMedinaPro.ClassEnumerator;

// Get all classes implementing IPlugin
var plugins = EnumerateClasses<IPlugin>.GetClassesByInterface();

foreach (var plugin in plugins)
    plugin.Run();

Note: the NuGet package is MarcusMedina.Reflection.ClassEnumerator, but the C# namespace is still MarcusMedinaPro.ClassEnumerator — it never changed when the package was renamed.

Links

Clone this wiki locally