public override PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            PropertyDescriptorCollection descriptorCollection = base.GetItemProperties(listAccessors);

            bool locationColumnsAdded = false;

            for (int i = 0; i < descriptorCollection.Count; i++)
            {
                var descriptor = descriptorCollection[i];

                if (locationColumnsAdded)
                {
                    ((FunctionBindingListPropertyDescriptor)descriptor).index += 1;
                    continue;
                }

                if (descriptor.PropertyType == typeof(INetworkLocation))
                {
                    descriptorCollection.RemoveAt(i); //remove network location, add two entries instead
                    descriptorCollection.Insert(i, new FunctionBindingListPropertyDescriptor(ColumnNameBranch, DisplayNameBranch, typeof(IBranch), i));
                    i++;
                    descriptorCollection.Insert(i, new FunctionBindingListPropertyDescriptor(ColumnNameOffset, DisplayNameOffset, typeof(double), i));
                    locationColumnsAdded = true;
                }
            }

            return(descriptorCollection);
        }
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            var descriptors = new PropertyDescriptorCollection(null);

            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(_properties);

            foreach (PropertyDescriptor eachProperty in properties)
            {
                descriptors.Add(
                    _customisations.ContainsKey(eachProperty.Name)
                                                ? new CustomPropertyDescriptor(eachProperty, _customisations[eachProperty.Name])
                                                : eachProperty);
            }

            var nonBrowsables = _customisations.Where(c => !c.Value.IsBrowsable);

            nonBrowsables.ForEach(a => descriptors.Remove(descriptors[a.Key]));

            //put Position property on top
            PropertyDescriptor positionDescriptor = descriptors["Position"];

            descriptors.Remove(positionDescriptor);

            descriptors.Insert(0, positionDescriptor);

            return(descriptors);
        }
示例#3
0
        public void ReadOnlyThrows()
        {
            var collection = new PropertyDescriptorCollection(null, true);

            // The readonly check occurs before anything else, so we don't need to pass in actual valid values
            Assert.Throws <NotSupportedException>(() => collection.Add(null));
            Assert.Throws <NotSupportedException>(() => collection.Insert(1, null));
            Assert.Throws <NotSupportedException>(() => collection.RemoveAt(1));
            Assert.Throws <NotSupportedException>(() => collection.Remove(null));
            Assert.Throws <NotSupportedException>(() => collection.Clear());
        }
        public void ReadOnlyThrows()
        {
            var collection = new PropertyDescriptorCollection(null, true);

            // The readonly check occurs before anything else, so we don't need to pass in actual valid values
            Assert.Throws<NotSupportedException>(() => collection.Add(null));
            Assert.Throws<NotSupportedException>(() => collection.Insert(1, null));
            Assert.Throws<NotSupportedException>(() => collection.RemoveAt(1));
            Assert.Throws<NotSupportedException>(() => collection.Remove(null));
            Assert.Throws<NotSupportedException>(() => collection.Clear());
        }
        public void collection_cannot_be_mutated()
        {
            var property0 = PropertyDescriptor.For(typeof(DecoratedType).GetProperty("Property0"));
            var property1 = PropertyDescriptor.For(typeof(DecoratedType).GetProperty("Property1"));
            IList<PropertyDescriptor> collection = new PropertyDescriptorCollection(new[] { property0, property1 });

            Assert.Throws<NotSupportedException>(() => collection.Add(property1));
            Assert.Throws<NotSupportedException>(() => collection.Clear());
            Assert.Throws<NotSupportedException>(() => collection.Insert(0, property1));
            Assert.Throws<NotSupportedException>(() => collection.Remove(property0));
            Assert.Throws<NotSupportedException>(() => collection.RemoveAt(0));
        }
示例#6
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            var pdc = new PropertyDescriptorCollection(new PropertyDescriptor[0]);

            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(this))
            {
                pdc.Add(pd);
            }

            //put Position property on top
            var posd = pdc["pPosition"];

            pdc.Remove(posd);
            pdc.Insert(0, posd);

            foreach (var key in CustomProperties.Keys)
            {
                pdc.Add(new DictionaryPropertyDescriptor(CustomProperties, key, attributes));
            }
            return(pdc);
        }
示例#7
0
        private void AssertReadOnly(PropertyDescriptorCollection descriptors, string testCase)
        {
            MockPropertyDescriptor mockPropertyDescr = new MockPropertyDescriptor(
                "Date", DateTime.Now);

            try {
                descriptors.Add(mockPropertyDescr);
                Assert.Fail(testCase + "#1");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            // ensure read-only check if performed before value is checked
            try {
                descriptors.Add(null);
                Assert.Fail(testCase + "#2");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                descriptors.Clear();
                Assert.Fail(testCase + "#3");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                descriptors.Insert(0, mockPropertyDescr);
                Assert.Fail(testCase + "#4");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            // ensure read-only check if performed before value is checked
            try {
                descriptors.Insert(0, null);
                Assert.Fail(testCase + "#5");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                descriptors.Remove(mockPropertyDescr);
                Assert.Fail(testCase + "#6");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            // ensure read-only check if performed before value is checked
            try {
                descriptors.Remove(null);
                Assert.Fail(testCase + "#7");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                descriptors.RemoveAt(0);
                Assert.Fail(testCase + "#8");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            IList list = (IList)descriptors;

            Assert.IsTrue(((IList)descriptors).IsReadOnly, testCase + "#9");
            Assert.IsTrue(((IList)descriptors).IsFixedSize, testCase + "#10");

            try {
                list.Add(mockPropertyDescr);
                Assert.Fail(testCase + "#11");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            // ensure read-only check if performed before value is checked
            try {
                list.Add(null);
                Assert.Fail(testCase + "#12");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                list.Clear();
                Assert.Fail(testCase + "#13");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                list.Insert(0, mockPropertyDescr);
                Assert.Fail(testCase + "#14");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            // ensure read-only check if performed before value is checked
            try {
                list.Insert(0, null);
                Assert.Fail(testCase + "#15");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                list.Remove(mockPropertyDescr);
                Assert.Fail(testCase + "#16");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            // ensure read-only check if performed before value is checked
            try {
                list.Remove(null);
                Assert.Fail(testCase + "#17");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                list.RemoveAt(0);
                Assert.Fail(testCase + "#18");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                list[0] = mockPropertyDescr;
                Assert.Fail(testCase + "#19");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            // ensure read-only check if performed before value is checked
            try {
                list[0] = null;
                Assert.Fail(testCase + "#20");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            IDictionary dictionary = (IDictionary)descriptors;

            Assert.IsTrue(dictionary.IsReadOnly, testCase + "#21");
            Assert.IsTrue(dictionary.IsFixedSize, testCase + "#22");

            try {
                dictionary.Add("test", mockPropertyDescr);
                Assert.Fail(testCase + "#23");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            // value is checked before read-only check
            try {
                dictionary.Add("test", null);
                Assert.Fail(testCase + "#24");
            } catch (ArgumentException) {
                // read-only collection cannot be modified
            }

            try {
                dictionary.Clear();
                Assert.Fail(testCase + "#25");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            try {
                dictionary[0] = mockPropertyDescr;
                Assert.Fail(testCase + "#26");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            // ensure read-only check if performed before value is checked
            try {
                dictionary[0] = null;
                Assert.Fail(testCase + "#27");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }
        }