要检查类型是否是C#中另一种类型的子类,很容易:
typeof (SubClass).IsSubclassOf(typeof (BaseClass)); // returns true
Run Code Online (Sandbox Code Playgroud)
但是,这将失败:
typeof (BaseClass).IsSubclassOf(typeof (BaseClass)); // returns false
Run Code Online (Sandbox Code Playgroud)
有没有办法检查类型是否是基类本身的子类OR,而不使用OR运算符或使用扩展方法?