public static bool IsTypeArgInSubclass(TypeDefinition thisTypeDefinition, TypeDefinition typeArgDefinition, IEmitter emitter, bool deep = true) { foreach (TypeReference interfaceReference in thisTypeDefinition.Interfaces) { var gBaseType = interfaceReference as GenericInstanceType; if (gBaseType != null && Helpers.HasGenericArgument(gBaseType, typeArgDefinition, emitter)) { return(true); } } if (thisTypeDefinition.BaseType != null) { TypeDefinition baseTypeDefinition = null; var gBaseType = thisTypeDefinition.BaseType as GenericInstanceType; if (gBaseType != null && Helpers.HasGenericArgument(gBaseType, typeArgDefinition, emitter)) { return(true); } try { baseTypeDefinition = Helpers.ToTypeDefinition(thisTypeDefinition.BaseType, emitter); } catch { } if (baseTypeDefinition != null && deep) { return(Helpers.IsTypeArgInSubclass(baseTypeDefinition, typeArgDefinition, emitter)); } } return(false); }