private static bool GenericIsMatch(Type candidate, Type value)
{
if(candidate.IsInterface)
{
var interfaces = value.GetInterfaces();
if(Array.IndexOf(interfaces, candidate) != -1)
{
return true;
}
}
while(value != null && value != typeof(object))
{
if(value == candidate)
{
return true;
}
value = value.BaseType;
if(!value.IsGenericType)
{
break;
}
value = value.GetGenericTypeDefinition();
}
return false;
}