示例#1
0
        public void ShoudReturnEmptyAttributeSequence()
        {
            var attributes = PropertyGridUtils.GetAttributes <BrowsablePropertyAttribute>(typeof(PropertyGridUtilsTestCase));

            Assert.IsNotNull(attributes);
            Assert.AreEqual <int>(0, attributes.Count());
        }
        public void SetProperties(Object obj)
        {
            propertyGrid1.SelectedObject = obj;

            if(obj!=null)
            descriptor = new PropertyGridUtils(obj.GetType());

            Invalidate();
        }
示例#3
0
        public void SetProperties(Object obj)
        {
            propertyGrid1.SelectedObject = obj;

            if (obj != null)
            {
                descriptor = new PropertyGridUtils(obj.GetType());
            }

            Invalidate();
        }
示例#4
0
        [Ignore] // TODO: This test is not reliable as Reflection does not always return the same order
        public void ShouldReturnAttributesByInstance()
        {
            var attributes = PropertyGridUtils.GetAttributes <BrowsableCategoryAttribute>(new PropertyGridUtilsTestCase());

            Assert.AreEqual <int>(2, attributes.Count());

            Assert.AreEqual <string>("category1", attributes.First().CategoryName);
            Assert.IsFalse(attributes.First().Browsable);

            Assert.AreEqual <string>("category2", attributes.Last().CategoryName);
            Assert.IsTrue(attributes.Last().Browsable);
        }
示例#5
0
        public CollectionItemValue(PropertyItemValue propertyItemValue, int index)
        {
            _propertyItemValue = propertyItemValue;
            _index             = index;

            var expandable = PropertyGridUtils.GetAttributes <ExpandableObjectAttribute>(Value);

            if (expandable.Any())
            {
                var descriptors = MetadataRepository.GetProperties(Value).Select(prop => prop.Descriptor);

                if (descriptors.Any())
                {
                    object objectValue;
                    if (Value is ICloneable valueToClone)
                    {
                        objectValue = valueToClone.Clone();
                    }
                    else
                    {
                        objectValue = Value;
                    }


                    HasSubProperties = true;

                    var properties = new GridEntryCollection <PropertyItem>();
                    foreach (PropertyDescriptor d in descriptors)
                    {
                        var item = new PropertyItem(_propertyItemValue.ParentProperty.Owner, objectValue, d);
                        item.IsBrowsable   = ShouldDisplayProperty(d);
                        item.ValueChanged += ItemOnValueChanged;
                        properties.Add(item);
                    }

                    if (_propertyItemValue.ParentProperty.Owner.PropertyComparer != null)
                    {
                        properties.Sort(_propertyItemValue.ParentProperty.Owner.PropertyComparer);
                    }

                    SubProperties = properties;
                }

                MetadataRepository.Remove(Value);
            }
        }
        internal void DoReload()
        {
            if (SelectedObject == null)
            {
                Categories = new GridEntryCollection <CategoryItem>();
                Properties = new GridEntryCollection <PropertyItem>();
            }
            else
            {
                // Collect BrowsableCategoryAttribute items
                var categoryAttributes = PropertyGridUtils.GetAttributes <BrowsableCategoryAttribute>(SelectedObject);
                browsableCategories = new List <BrowsableCategoryAttribute>(categoryAttributes);

                // Collect BrowsablePropertyAttribute items
                var propertyAttributes = PropertyGridUtils.GetAttributes <BrowsablePropertyAttribute>(SelectedObject);
                browsableProperties = new List <BrowsablePropertyAttribute>(propertyAttributes);

                // Collect categories and properties
                var properties = CollectProperties(SelectedObjects);

                // TODO: This needs more elegant implementation
                var categories = new GridEntryCollection <CategoryItem>(CollectCategories(properties));
                if (Categories != null && Categories.Count > 0)
                {
                    CopyCategoryFrom(Categories, categories);
                }

                // Fetch and apply category orders
                var categoryOrders = PropertyGridUtils.GetAttributes <CategoryOrderAttribute>(SelectedObject);
                foreach (var orderAttribute in categoryOrders)
                {
                    var category = categories[orderAttribute.Category];
                    // don't apply Order if it was applied before (Order equals zero or more),
                    // so the first discovered Order value for the same category wins
                    if (category != null && category.Order < 0)
                    {
                        category.Order = orderAttribute.Order;
                    }
                }

                Categories = categories; //new CategoryCollection(CollectCategories(properties));
                Properties = new GridEntryCollection <PropertyItem>(properties);
            }
        }
示例#7
0
 public void ShouldFailForNullType()
 {
     PropertyGridUtils.GetAttributes <BrowsableCategoryAttribute>((Type)null);
 }
示例#8
0
 public void ShouldFailForNullObject()
 {
     PropertyGridUtils.GetAttributes <BrowsableCategoryAttribute>((object)null);
 }