/// <summary>
        /// Returns true if the given dataType matches the given behaviorType. If the dataType is
        /// generic and the behaviorType is a generic definition, then the behaviorType will be
        /// instantiated with the same generic arguments as dataType.
        /// </summary>
        private static bool CanEdit(Type dataType, CustomBehaviorEditorAttribute behaviorTypeAttribute)
        {
            if (behaviorTypeAttribute == null) {
                return true;
            }

            Type behaviorType = behaviorTypeAttribute.BehaviorType;
            if (dataType.IsGenericType && behaviorType.IsGenericTypeDefinition) {
                // I don't believe this will ever throw, but just in case we wrap it in a try/catch
                // block.
                try {
                    behaviorType = behaviorType.MakeGenericType(dataType.GetGenericArguments());
                }
                catch { }
            }

            return dataType == behaviorType ||
                (behaviorTypeAttribute.Inherit && behaviorType.IsAssignableFrom(dataType));
        }
Пример #2
0
        /// <summary>
        /// Returns true if the given dataType matches the given behaviorType. If the dataType is
        /// generic and the behaviorType is a generic definition, then the behaviorType will be
        /// instantiated with the same generic arguments as dataType.
        /// </summary>
        private static bool CanEdit(Type dataType, CustomBehaviorEditorAttribute behaviorTypeAttribute)
        {
            if (behaviorTypeAttribute == null)
            {
                return(true);
            }

            Type behaviorType = behaviorTypeAttribute.BehaviorType;

            if (dataType.IsGenericType && behaviorType.IsGenericTypeDefinition)
            {
                // I don't believe this will ever throw, but just in case we wrap it in a try/catch
                // block.
                try {
                    behaviorType = behaviorType.MakeGenericType(dataType.GetGenericArguments());
                }
                catch { }
            }

            return(dataType == behaviorType ||
                   (behaviorTypeAttribute.Inherit && behaviorType.IsAssignableFrom(dataType)));
        }