Ejemplo n.º 1
0
        public void GetProperties()
        {
            PropertyDescriptorCollection properties = null;
            C             c         = new C();
            TypeConverter converter = TypeDescriptor.GetConverter(c);

            Assert.AreEqual(typeof(AConverter).FullName, converter.GetType().FullName, "#1");

            properties = converter.GetProperties(c);
            Assert.AreEqual(1, properties.Count, "#2");
            Assert.AreEqual("A", properties[0].Name, "#3");

            // ensure collection is read-only
            try {
                properties.Clear();
                Assert.Fail("#4");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            properties = converter.GetProperties(null, c);
            Assert.AreEqual(1, properties.Count, "#5");
            Assert.AreEqual("A", properties[0].Name, "#6");


            // ensure collection is read-only
            try {
                properties.Clear();
                Assert.Fail("#7");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            properties = converter.GetProperties(null, c, null);
            Assert.AreEqual(2, properties.Count, "#8");

            // ensure collection is read-only
            try {
                properties.Clear();
                Assert.Fail("#9");
            } catch (NotSupportedException) {
                // read-only collection cannot be modified
            }

            properties = converter.GetProperties(null);
            Assert.IsNull(properties, "#10");

            properties = converter.GetProperties(null, null);
            Assert.IsNull(properties, "#11");

            properties = converter.GetProperties(null, null, null);
            Assert.IsNull(properties, "#12");
        }
Ejemplo n.º 2
0
        private void FilterProperties(string filter)
        {
            _FilteredPropertyDescriptors.Clear();
            List <string> props = new List <string>(); // = filter.Split(';');

            props.AddRange(filter.Split(';'));

            foreach (string p in props)
            {
                PropertyDescriptor descriptor = _FullPropertyDescriptors.Find(p, true);
                if (descriptor != null)
                {
                    _FilteredPropertyDescriptors.Add(descriptor);
                }
                else
                {
                    descriptor = _FullPropertyDescriptors.Find(p.ArrayName(), true);
                    if (descriptor != null)
                    {
                        if (_FilteredPropertyDescriptors.IndexOf(descriptor) < 0)
                        {
                            _FilteredPropertyDescriptors.Add(descriptor);
                        }
                    }
                }
            }
        }
Ejemplo n.º 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));
        }
        private void PreProcess(PropertyDescriptorCollection pdc)
        {
            if (pdc.Count <= 0)
            {
                return;
            }
            UpdateStringFromResource(pdc);

            var propSorter = new PropertySorter
            {
                CategorySortOrder = CategorySortOrder,
                PropertySortOrder = PropertySortOrder
            };
            var pdcSorted = pdc.Sort(propSorter);

            UpdateAppendCount(pdcSorted);

            pdc.Clear();
            foreach (PropertyDescriptor pd in pdcSorted)
            {
                pdc.Add(pd);
            }
        }
Ejemplo n.º 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
            }
        }
 public void ResetProperties()
 {
     m_pdc.Clear();
     GetProperties();
 }