Consider the following code:
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());
}
}
What is the best way to implement IsDescendantOf?
Type.IsSubclassOf() Determines whether the class represented by the current Type derives from the class represented by the specified Type.
You are probably looking for Type.IsAssignableFrom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With