考虑以下代码:
public class A
{
}
public class B : A
{
}
public class C : B
{
}
class D
{
public static bool IsDescendantOf(this System.Type thisType, System.Type thatType)
{
/// ???
}
void Main()
{
A cValue = new C();
C.GetType().IsDescendantOf(cValue.GetType());
}
}
实现 IsDescendantOf 的最佳方法是什么?
最佳答案
Type.IsSubclassOf()判断当前Type表示的类是否派生自指定Type表示的类。
关于c# - 检查 System.Type 是否是给定类的后代的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1433750/