public static bool InheritsGenericDefinition( Type type, Type genericClassDefinition, out Type implementingType) { ValidationUtils.ArgumentNotNull((object)type, nameof(type)); ValidationUtils.ArgumentNotNull((object)genericClassDefinition, nameof(genericClassDefinition)); if (!genericClassDefinition.IsClass() || !genericClassDefinition.IsGenericTypeDefinition()) { throw new ArgumentNullException( "'{0}' is not a generic class definition.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture, (object)genericClassDefinition)); } return(ReflectionUtils.InheritsGenericDefinitionInternal(type, genericClassDefinition, out implementingType)); }
private static bool InheritsGenericDefinitionInternal( Type currentType, Type genericClassDefinition, out Type implementingType) { if (currentType.IsGenericType()) { Type genericTypeDefinition = currentType.GetGenericTypeDefinition(); if (genericClassDefinition == genericTypeDefinition) { implementingType = currentType; return(true); } } if (currentType.BaseType() != null) { return(ReflectionUtils.InheritsGenericDefinitionInternal(currentType.BaseType(), genericClassDefinition, out implementingType)); } implementingType = (Type)null; return(false); }