2007-08-19 Ivan N. Zlatev <contact@i-nz.net>
authorIvan Zlatev <ivan@ivanz.com>
Sun, 19 Aug 2007 10:08:37 +0000 (10:08 -0000)
committerIvan Zlatev <ivan@ivanz.com>
Sun, 19 Aug 2007 10:08:37 +0000 (10:08 -0000)
* 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

mcs/class/System/System.ComponentModel/ChangeLog
mcs/class/System/System.ComponentModel/TypeDescriptor.cs
mcs/class/System/System_test.dll.sources
mcs/class/System/Test/System.ComponentModel/ChangeLog
mcs/class/System/Test/System.ComponentModel/TypeDescriptorTests.cs

index 6bd46073a20264bb30b1266efe8368dc95af046d..d77ab9d658ad5323d21a61a8c6d8e3dde489d4fb 100644 (file)
@@ -1,3 +1,8 @@
+2007-08-19  Ivan N. Zlatev  <contact@i-nz.net>
+
+       * 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  <jbevain@novell.com>
 
        * ComponentCollection.cs: use our own collection base
index 1e0942b9709d1b8272fe9c4fb4342262743b4abb..8704a90618385856e983fa6141f9e34820975c6a 100644 (file)
@@ -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<props.Length; n++)
+                       Hashtable descs = new Hashtable ();
+                       for (int n= props.Length-1; 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;
                }
        }
index a8cc9fe1c56e130afb704de0ec38968cbaa14141..342fc3b87db7445e6d2996e1813f4b28f43eaa7e 100644 (file)
@@ -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
index 537f0d725727b3bf52a5aca720bdb02b1ecd06b1..1aab2b91d73f279f8b421eebc15c5deb8eedc7d7 100644 (file)
@@ -1,3 +1,9 @@
+2007-08-19  Ivan N. Zlatev  <contact@i-nz.net>
+
+       * 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  <atsushi@ximian.com>
 
        * BackgroundWorkerTest.cs : new test to clear some doubts on impl.
index ce887c7ea82524f97e6ecc1c225807e1db6487fb..52e17280dd27e6d4203d80677fedd55e750429ac 100644 (file)
@@ -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]