public static class TypeExtensions
{
public static bool IsAssignableFromGeneric(this Type @base, Type derived)
{
var interfaceTypes = derived.GetInterfaces();
foreach (var it in interfaceTypes)
{
if (it.IsGenericType && it.GetGenericTypeDefinition() == @base)
return true;
}
if (derived.IsGenericType && derived.GetGenericTypeDefinition() == @base)
return true;
Type baseType = derived.BaseType;
if (baseType == null) return false;
return IsAssignableFromGeneric(@base, baseType);
}
}