internal object ComputeDescriptionForItem(object item)
        {
            PropertyDescriptor pd = item as PropertyDescriptor;

            //We do not simply rely on the "Description" property of PropertyDescriptor
            //since this value is cached by PropertyDescriptor and the localized version
            //(e.g., LocalizedDescriptionAttribute) value can dynamicaly change.
#if !VS2008
            var displayAttribute = PropertyGridUtilities.GetAttribute <DisplayAttribute>(pd);
            if (displayAttribute != null)
            {
                return(displayAttribute.GetDescription());
            }
#endif

            var descriptionAtt = PropertyGridUtilities.GetAttribute <DescriptionAttribute>(pd);
            return((descriptionAtt != null)
              ? descriptionAtt.Description
              : pd.Description);
        }
        internal static Predicate <object> CreateFilter(string text, IList <PropertyItem> PropertyItems, IPropertyContainer propertyContainer)
        {
            Predicate <object> filter = null;

            if (!string.IsNullOrEmpty(text))
            {
                filter = (item) =>
                {
                    var property = item as PropertyItem;
                    if (property.DisplayName != null)
                    {
#if !VS2008
                        var displayAttribute = PropertyGridUtilities.GetAttribute <DisplayAttribute>(property.PropertyDescriptor);
                        if (displayAttribute != null)
                        {
                            var canBeFiltered = displayAttribute.GetAutoGenerateFilter();
                            if (canBeFiltered.HasValue && !canBeFiltered.Value)
                            {
                                return(false);
                            }
                        }
#endif
                        property.HighlightedText = property.DisplayName.ToLower().Contains(text.ToLower()) ? text : null;
                        return(property.HighlightedText != null);
                    }

                    return(false);
                };
            }
            else
            {
                ClearFilterSubItems(PropertyItems.ToList());
            }

            return(filter);
        }
Пример #3
0
        protected override void GenerateSubPropertiesCore(Action <IEnumerable <PropertyItem> > updatePropertyItemsCallback)
        {
            var propertyItems = new List <PropertyItem>();

            if (SelectedObject != null)
            {
                try
                {
                    var descriptors = new List <PropertyDescriptor>();
                    {
                        descriptors = ObjectContainerHelperBase.GetPropertyDescriptors(SelectedObject, this.PropertyContainer.HideInheritedProperties);
                    }

                    foreach (var descriptor in descriptors)
                    {
                        var  propertyDef = this.GetPropertyDefinition(descriptor);
                        bool isBrowsable = false;

                        var isPropertyBrowsable = this.PropertyContainer.IsPropertyVisible(descriptor);
                        if (isPropertyBrowsable.HasValue)
                        {
                            isBrowsable = isPropertyBrowsable.Value;
                        }
                        else
                        {
#if !VS2008
                            var displayAttribute = PropertyGridUtilities.GetAttribute <DisplayAttribute>(descriptor);
                            if (displayAttribute != null)
                            {
                                var autoGenerateField = displayAttribute.GetAutoGenerateField();
                                isBrowsable = this.PropertyContainer.AutoGenerateProperties &&
                                              ((autoGenerateField.HasValue && autoGenerateField.Value) || !autoGenerateField.HasValue);
                            }
                            else
#endif
                            {
                                isBrowsable = descriptor.IsBrowsable && this.PropertyContainer.AutoGenerateProperties;
                            }

                            if (propertyDef != null)
                            {
                                isBrowsable = propertyDef.IsBrowsable.GetValueOrDefault(isBrowsable);
                            }
                        }

                        if (isBrowsable)
                        {
                            var prop = this.CreatePropertyItem(descriptor, propertyDef);
                            if (prop != null)
                            {
                                propertyItems.Add(prop);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    //TODO: handle this some how
                    Debug.WriteLine("Property creation failed.");
                    Debug.WriteLine(e.StackTrace);
                }
            }

            updatePropertyItemsCallback.Invoke(propertyItems);
        }
Пример #4
0
 private T GetAttribute <T>() where T : Attribute
 {
     return(PropertyGridUtilities.GetAttribute <T>(PropertyDescriptor));
 }