From e87604097845dbe71577e2792ee771711f34791e Mon Sep 17 00:00:00 2001 From: Ivan Zlatev Date: Sun, 19 Aug 2007 10:08:37 +0000 Subject: [PATCH] 2007-08-19 Ivan N. Zlatev * TypeDescriptor.cs: GetProperties should return only the last type's implementation of a property with a matching name in the base types. * TypeDescriptorTests.cs: test to verify the above. svn path=/trunk/mcs/; revision=84375 --- .../System/System.ComponentModel/ChangeLog | 5 +++++ .../System.ComponentModel/TypeDescriptor.cs | 14 +++++++----- mcs/class/System/System_test.dll.sources | 1 + .../Test/System.ComponentModel/ChangeLog | 6 +++++ .../TypeDescriptorTests.cs | 22 +++++++++++++++++++ 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/mcs/class/System/System.ComponentModel/ChangeLog b/mcs/class/System/System.ComponentModel/ChangeLog index 6bd46073a20..d77ab9d658a 100644 --- a/mcs/class/System/System.ComponentModel/ChangeLog +++ b/mcs/class/System/System.ComponentModel/ChangeLog @@ -1,3 +1,8 @@ +2007-08-19 Ivan N. Zlatev + + * TypeDescriptor.cs: GetProperties should return only the last type's + implementation of a property with a matching name in the base types. + 2007-08-03 Jb Evain * ComponentCollection.cs: use our own collection base diff --git a/mcs/class/System/System.ComponentModel/TypeDescriptor.cs b/mcs/class/System/System.ComponentModel/TypeDescriptor.cs index 1e0942b9709..8704a906183 100644 --- a/mcs/class/System/System.ComponentModel/TypeDescriptor.cs +++ b/mcs/class/System/System.ComponentModel/TypeDescriptor.cs @@ -1018,8 +1018,8 @@ public sealed class TypeDescriptor bool cache = true; PropertyInfo[] props = _component.GetType().GetProperties (BindingFlags.Instance | BindingFlags.Public); Hashtable t = new Hashtable (); - foreach (PropertyInfo pr in props) - t [pr.Name] = new ReflectionPropertyDescriptor (pr); + for (int i = props.Length-1; i >= 0; i--) + t [props[i].Name] = new ReflectionPropertyDescriptor (props[i]); if (_component.Site != null) { @@ -1071,12 +1071,14 @@ public sealed class TypeDescriptor return _properties; PropertyInfo[] props = InfoType.GetProperties (BindingFlags.Instance | BindingFlags.Public); - ArrayList descs = new ArrayList (props.Length); - for (int n=0; n= 0; n--) if (props [n].GetIndexParameters ().Length == 0) - descs.Add (new ReflectionPropertyDescriptor (props[n])); + descs[props[n].Name] = new ReflectionPropertyDescriptor (props[n]); - _properties = new PropertyDescriptorCollection ((PropertyDescriptor[]) descs.ToArray (typeof (PropertyDescriptor)), true); + PropertyDescriptor[] descriptors = new PropertyDescriptor[descs.Values.Count]; + descs.Values.CopyTo (descriptors, 0); + _properties = new PropertyDescriptorCollection (descriptors, true); return _properties; } } diff --git a/mcs/class/System/System_test.dll.sources b/mcs/class/System/System_test.dll.sources index a8cc9fe1c56..342fc3b87db 100644 --- a/mcs/class/System/System_test.dll.sources +++ b/mcs/class/System/System_test.dll.sources @@ -138,6 +138,7 @@ System.ComponentModel/UInt16ConverterTests.cs System.ComponentModel/UInt32ConverterTests.cs System.ComponentModel/UInt64ConverterTests.cs System.ComponentModel.Design/ServiceContainerTest.cs +System.ComponentModel.Design.Serialization/ContextStackTest.cs System.ComponentModel.Design.Serialization/InstanceDescriptorTest.cs System.Configuration/ApplicationSettingsBaseTest.cs System.Configuration/LocalFileSettingsProviderTest.cs diff --git a/mcs/class/System/Test/System.ComponentModel/ChangeLog b/mcs/class/System/Test/System.ComponentModel/ChangeLog index 537f0d72572..1aab2b91d73 100644 --- a/mcs/class/System/Test/System.ComponentModel/ChangeLog +++ b/mcs/class/System/Test/System.ComponentModel/ChangeLog @@ -1,3 +1,9 @@ +2007-08-19 Ivan N. Zlatev + + * TypeDescriptorTest.cs: new test to verify that GetProperties returns + only the last type's implementation of a property with a matching name + in the base types. + 2007-08-01 Atsushi Enomoto * BackgroundWorkerTest.cs : new test to clear some doubts on impl. diff --git a/mcs/class/System/Test/System.ComponentModel/TypeDescriptorTests.cs b/mcs/class/System/Test/System.ComponentModel/TypeDescriptorTests.cs index ce887c7ea82..52e17280dd2 100644 --- a/mcs/class/System/Test/System.ComponentModel/TypeDescriptorTests.cs +++ b/mcs/class/System/Test/System.ComponentModel/TypeDescriptorTests.cs @@ -248,6 +248,14 @@ namespace MonoTests.System.ComponentModel get { return prop; } set { prop = value; } } + + + [DescriptionAttribute ("test derived")] + public new string AnotherProperty + { + get { return base.AnotherProperty; } + set { base.AnotherProperty = value; } + } } @@ -379,6 +387,7 @@ namespace MonoTests.System.ComponentModel } [TestFixture] + [NUnit.Framework.Category ("inz")] public class TypeDescriptorTests { MyComponent com = new MyComponent (); @@ -720,6 +729,19 @@ namespace MonoTests.System.ComponentModel col = TypeDescriptor.GetProperties (nfscom, filter); Assert.IsNotNull (col.Find ("TestProperty", true), "#F1"); Assert.IsNull (col.Find ("AnotherProperty", true), "#F2"); + + + // GetProperties should return only the last type's implementation of a + // property with a matching name in the base types. E.g in the case where + // the "new" keyword is used. + // + PropertyDescriptorCollection derivedCol = TypeDescriptor.GetProperties (typeof(MyDerivedComponent)); + Assert.IsNotNull (derivedCol["AnotherProperty"].Attributes[typeof (DescriptionAttribute)], "#G1"); + int propsFound = 0; + foreach (PropertyDescriptor props in derivedCol) + if (props.Name == "AnotherProperty") + propsFound++; + Assert.AreEqual (1, propsFound, "#G2"); } [Test] -- 2.25.1