In C#, how do I check if a type is a subtype OR the type of an object?
- by Daniel T.
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?