It might be overkill but I use extension methods like the following. They check interfaces as well as subclasses. It can also return the type that has the specified generic defintion.
E.g. for the example in the question it can test against GenericInterface as well as GenericClass. The returned type can be used with GetGenericArguments to determine that the generic argument type is "SomeType".
public static bool HasGenericDefinition(this Type type, Type definition)
{
return GetTypeWithGenericDefinition(type, definition) != null;
}
public static Type GetTypeWithGenericDefinition(this Type type, Type definition)
{
if (type == null)
throw new ArgumentNullException("type");
if (definition == null)
throw new ArgumentNullException("genericTypeDefinition");
if (!definition.IsGenericTypeDefinition)
throw new ArgumentException(
"The definition needs to be a GenericTypeDefinition", "definition");
if (definition.IsInterface)
foreach (var interfaceType in type.GetInterfaces())
if (interfaceType.IsGenericType
&& interfaceType.GetGenericTypeDefinition() == definition)
return interfaceType;
for (Type t = type; t != null; t = t.BaseType)
if (t.IsGenericType
&& t.GetGenericTypeDefinition() == definition)
return t;
return null;
}