I have a custom control and a number of controls derived from it. I need to get all classes in the current assembly that are derived from the main class and check their attributes. How to accomplish this?
var type = typeof(MainClass);
var listOfDerivedClasses = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(x => x.IsSubclassOf(type))
.ToList();
foreach (var derived in listOfDerivedClasses)
{
var attributes = derived.GetCustomAttributes(typeof(TheAttribute), true);
// etc.
}
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