How do you get a collection of all the types that inherit from a specific other type?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Something like:
If you need to handle generics, that gets somewhat trickier (e.g. passing in the open
List<>type but expecting to get back a type which derived fromList<int>). Otherwise it’s simple though 🙂If you want to exclude the type itself, you can do so easily enough:
Note that this will also allow you to specify an interface and find all the types which implement it, rather than just working with classes as
Type.IsSubclassOfdoes.