public static Type FindGenericType(Type definition, Type type)
{
while (type != null && type != typeof(object))
{
if (type.IsConstructedGenericType && AreEquivalent(type.GetGenericTypeDefinition(), definition))
{
return type;
}
if (definition.GetTypeInfo().IsInterface)
{
foreach (Type itype in type.GetTypeInfo().ImplementedInterfaces)
{
Type found = FindGenericType(definition, itype);
if (found != null)
return found;
}
}
type = type.GetTypeInfo().BaseType;
}
return null;
}