Example #1
0
        protected virtual bool Filter(PropertyGridDataTemplate template, PropertyGridProperty property)
        {
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }

            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            // check various filters
            if (template.IsCollection.HasValue && template.IsCollection.Value != property.IsCollection)
            {
                return(true);
            }

            if (template.IsCollectionItemValueType.HasValue && template.IsCollectionItemValueType.Value != property.IsCollectionItemValueType)
            {
                return(true);
            }

            if (template.IsValueType.HasValue && template.IsValueType.Value != property.IsValueType)
            {
                return(true);
            }

            if (template.IsReadOnly.HasValue && template.IsReadOnly.Value != property.IsReadOnly)
            {
                return(true);
            }

            if (template.IsError.HasValue && template.IsError.Value != property.IsError)
            {
                return(true);
            }

            if (template.IsValid.HasValue && template.IsValid.Value != property.IsValid)
            {
                return(true);
            }

            if (template.IsFlagsEnum.HasValue && template.IsFlagsEnum.Value != property.IsFlagsEnum)
            {
                return(true);
            }

            if (template.Category != null && !property.Category.EqualsIgnoreCase(template.Category))
            {
                return(true);
            }

            if (template.Name != null && !property.Name.EqualsIgnoreCase(template.Name))
            {
                return(true);
            }

            return(false);
        }
        protected virtual bool Filter(PropertyGridDataTemplate template, PropertyGridProperty property)
        {
            if (template == null)
                throw new ArgumentNullException("template");

            if (property == null)
                throw new ArgumentNullException("property");

            // check various filters
            if (template.IsCollection.HasValue && template.IsCollection.Value != property.IsCollection)
            {
                return true;
            }

            if (template.IsCollectionItemValueType.HasValue && template.IsCollectionItemValueType.Value != property.IsCollectionItemValueType)
            {
                return true;
            }

            if (template.IsValueType.HasValue && template.IsValueType.Value != property.IsValueType)
            {
                return true;
            }

            if (template.IsReadOnly.HasValue && template.IsReadOnly.Value != property.IsReadOnly)
            {
                return true;
            }

            if (template.IsError.HasValue && template.IsError.Value != property.IsError)
            {
                return true;
            }

            if (template.IsValid.HasValue && template.IsValid.Value != property.IsValid)
            {
                return true;
            }

            if (template.IsFlagsEnum.HasValue && template.IsFlagsEnum.Value != property.IsFlagsEnum)
            {
                return true;
            }

            if (template.Category != null && !property.Category.EqualsIgnoreCase(template.Category))
            {
                return true;
            }

            if (template.Name != null && !property.Name.EqualsIgnoreCase(template.Name))
            {
                return true;
            }

            return false;
        }
        public virtual bool IsAssignableFrom(Type type, Type propertyType, PropertyGridDataTemplate template, PropertyGridProperty property)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            if (propertyType == null)
                throw new ArgumentNullException("propertyType");

            if (template == null)
                throw new ArgumentNullException("template");

            if (property == null)
                throw new ArgumentNullException("property");

            if (type.IsAssignableFrom(propertyType))
            {
                // bool? is assignable from bool, but we don't want that match
                if (!type.IsNullable() || propertyType.IsNullable())
                    return true;
            }

            // hack for nullable enums...
            if (type == PropertyGridDataTemplate.NullableEnumType)
            {
                Type enumType;
                bool nullable;
                PropertyGridProperty.IsEnumOrNullableEnum(propertyType, out enumType, out nullable);
                if (nullable)
                    return true;
            }

            var options = PropertyGridOptionsAttribute.FromProperty(property);
            if (options != null)
            {
                if ((type.IsEnum || type == typeof(Enum)) && options.IsEnum)
                {
                    if (!options.IsFlagsEnum)
                        return true;

                    if (Extensions.IsFlagsEnum(type))
                        return true;

                    if (template.IsFlagsEnum.HasValue && template.IsFlagsEnum.Value)
                        return true;
                }
            }

            return false;
        }
Example #4
0
        public virtual bool IsAssignableFrom(Type type, Type propertyType, PropertyGridDataTemplate template, PropertyGridProperty property)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (propertyType == null)
            {
                throw new ArgumentNullException("propertyType");
            }

            if (template == null)
            {
                throw new ArgumentNullException("template");
            }

            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (type.IsAssignableFrom(propertyType))
            {
                // bool? is assignable from bool, but we don't want that match
                if (!type.IsNullable() || propertyType.IsNullable())
                {
                    return(true);
                }
            }

            // hack for nullable enums...
            if (type == PropertyGridDataTemplate.NullableEnumType)
            {
                Type enumType;
                bool nullable;
                PropertyGridProperty.IsEnumOrNullableEnum(propertyType, out enumType, out nullable);
                if (nullable)
                {
                    return(true);
                }
            }

            var options = PropertyGridOptionsAttribute.FromProperty(property);

            if (options != null)
            {
                if ((type.IsEnum || type == typeof(Enum)) && options.IsEnum)
                {
                    if (!options.IsFlagsEnum)
                    {
                        return(true);
                    }

                    if (Extensions.IsFlagsEnum(type))
                    {
                        return(true);
                    }

                    if (template.IsFlagsEnum.HasValue && template.IsFlagsEnum.Value)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }