In C#, how do I check if a type is a subtype OR the type of an object?

Posted by Daniel T. on Stack Overflow See other posts from Stack Overflow or by Daniel T.
Published on 2010-04-30T04:23:33Z Indexed on 2010/04/30 4:27 UTC
Read the original article Hit count: 235

Filed under:
|
|
|

To check if a type is a subclass of another type in C#, it's easy:

typeof (SubClass).IsSubclassOf(BaseClass); // returns true

However, this will fail:

typeof (BaseClass).IsSubclassOf(BaseClass); // returns false

Is there any way to check whether a type is either a subclass OR of the base class itself, without using an OR operator or using an extension method?

© Stack Overflow or respective owner

Related posts about c#

Related posts about type