Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
 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));
 }