How do I check (at runtime) if one class is a subclass of another?

Let’s say that I have a class Suit and four subclasses of suit: Heart, Spade, Diamond, Club. class Suit: … class Heart(Suit): … class Spade(Suit): … class Diamond(Suit): … class Club(Suit): … I have a method which receives a suit as a parameter, which is a class object, not an instance. More precisely, it may … Read more

How do I check if a type is a subtype OR the type of an object?

To check if a type is a subclass of another type in C#, it’s easy: typeof (SubClass).IsSubclassOf(typeof (BaseClass)); // returns true However, this will fail: typeof (BaseClass).IsSubclassOf(typeof (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 … Read more