/// <summary> /// Returns true if the given dataType matches the given propertyType. If the dataType is /// generic and the propertyType is a generic definition, then the propertyType will be /// instantiated with the same generic arguments as dataType. /// </summary> private static bool CanEdit(Type dataType, CustomPropertyEditorAttribute propertyTypeAttribute) { if (propertyTypeAttribute == null) { return true; } Type propertyType = propertyTypeAttribute.PropertyType; if (dataType.IsGenericType && propertyType.IsGenericTypeDefinition) { // I don't believe this will ever throw, but just in case we wrap it in a try/catch // block. try { propertyType = propertyType.MakeGenericType(dataType.GetGenericArguments()); } catch { } } return dataType == propertyType || (propertyTypeAttribute.Inherit && propertyType.IsAssignableFrom(dataType)); }
private static bool CanEdit(Type dataType, CustomPropertyEditorAttribute propertyTypeAttribute) { if (propertyTypeAttribute == null) { return true; } Type type = propertyTypeAttribute.PropertyType; if (dataType.IsGenericType && type.IsGenericTypeDefinition) { try { type = type.MakeGenericType(dataType.GetGenericArguments()); } catch { } } return dataType == type || (propertyTypeAttribute.Inherit && type.IsAssignableFrom(dataType)); }