I have a generic class in my project with derived classes.
public class GenericClass : GenericInterface
{
}
public class Test : GenericCla
JaredPar,
This did not work for me if I pass typeof(type<>) as toCheck. Here's what I changed.
static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {
while (toCheck != typeof(object)) {
var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
if (cur.IsGenericType && generic.GetGenericTypeDefinition() == cur.GetGenericTypeDefinition()) {
return true;
}
toCheck = toCheck.BaseType;
}
return false;
}