Question

In Java there are methods to go about scanning the classpath/all classes/within a package and enumerating the classes therein. e.g. spring component scanning uses something like this to scan all classes and find those with an interesting annotation.

If there any similar technique for C# and if so what are the APIs to use?

Was it helpful?

Solution

The Reflection API is the way you would do this via C#.

You can use the Assembly class to look at assemblies (ie: packages). Within the assembly, you can use Assembly.GetTypes to retrieve a list of all of the classes.

The first link above demonstrates quite a few options of how this can be used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top