Kaynağa Gözat

2006-09-11 Gonzalo Paniagua Javier <[email protected]>

	* Test/System.ComponentModel/TypeDescriptorTests.cs: test for overriden
	attributes.
	* System.ComponentModel/TypeDescriptor.cs: don't ignore toplevel
	attributes when they are overriden.

	Patch by Ivan N. Zlatev that fixes bug #79256.


svn path=/trunk/mcs/; revision=65242
Gonzalo Paniagua Javier 19 yıl önce
ebeveyn
işleme
35a49d5a64

+ 7 - 0
mcs/class/System/System.ComponentModel/ChangeLog

@@ -1,3 +1,10 @@
+2006-09-11 Gonzalo Paniagua Javier <[email protected]>
+
+	* TypeDescriptor.cs: don't ignore toplevel attributes when they are
+	overriden.
+
+	Patch by Ivan N. Zlatev that fixes bug #79256.
+
 2006-08-20  Gert Driesen  <[email protected]>
 
 	* InvalidEnumArgumentException.cs: Beautify error message.

+ 7 - 2
mcs/class/System/System.ComponentModel/TypeDescriptor.cs

@@ -705,8 +705,13 @@ public sealed class TypeDescriptor
 			bool cache = true;
 			object[] ats = _infoType.GetCustomAttributes (true);
 			Hashtable t = new Hashtable ();
-			foreach (Attribute at in ats)
-				t [at.TypeId] = at;
+
+			// Filter the custom attributes, so that only the top
+			// level of the same type are left.
+			//
+			for (int i = ats.Length -1; i >= 0; i--) {
+				t [((Attribute) ats[i]).TypeId] = ats[i];
+			}
 					
 			if (comp != null && comp.Site != null) 
 			{

+ 5 - 0
mcs/class/System/Test/System.ComponentModel/ChangeLog

@@ -1,3 +1,8 @@
+2006-09-11 Gonzalo Paniagua Javier <[email protected]>
+
+	* TypeDescriptorTests.cs: test for overriden attributes.
+	Patch by Ivan N. Zlatev.
+
 2006-05-22  Atsushi Enomoto  <[email protected]>
 
 	* TypeDescriptorTest.cs : added GetPropertiesIgnoreIndexers().

+ 44 - 1
mcs/class/System/Test/System.ComponentModel/TypeDescriptorTests.cs

@@ -32,6 +32,19 @@ namespace MonoTests.System.ComponentModel
 		public void Dispose () { }
 	}
 
+	class MyOtherDesigner: IDesigner
+	{
+		public MyOtherDesigner()
+		{
+		}
+
+		public IComponent Component {get {return null; } }
+		public DesignerVerbCollection Verbs { get {return null; } }
+		public void DoDefaultAction () { }
+		public void Initialize (IComponent component) { }
+		public void Dispose () { }
+	}
+	
 	class MySite: ISite
 	{ 
 		public IComponent Component { get {  return null; } }
@@ -136,7 +149,7 @@ namespace MonoTests.System.ComponentModel
 		}
 		
 		[DescriptionAttribute ("test")]
-		public string TestProperty
+		public virtual string TestProperty
 		{
 			get { return prop; }
 			set { prop = value; }
@@ -149,6 +162,29 @@ namespace MonoTests.System.ComponentModel
 		}
 	}
 
+	[DescriptionAttribute ("my test derived component")]
+	[DesignerAttribute (typeof(MyOtherDesigner))]
+	public class MyDerivedComponent: MyComponent
+	{
+		string prop;
+		
+		public MyDerivedComponent  ()
+		{
+		}
+		
+		public MyDerivedComponent (ISite site) : base (site)
+		{
+		}
+		
+		[DescriptionAttribute ("test derived")]
+		public override string TestProperty
+		{
+			get { return prop; }
+			set { prop = value; }
+		}
+	}
+	
+
 	[DefaultProperty("AnotherProperty")]
 	[DefaultEvent("AnotherEvent")]
 	[DescriptionAttribute ("my test component")]
@@ -256,6 +292,13 @@ namespace MonoTests.System.ComponentModel
 			Assert ("t10", col[typeof(DescriptionAttribute)] != null);
 			Assert ("t11", col[typeof(DesignerAttribute)] != null);
 			Assert ("t12", col[typeof(EditorAttribute)] != null);
+
+			col = TypeDescriptor.GetAttributes (typeof (MyDerivedComponent));
+			Assert ("t13", col[typeof(DesignerAttribute)] != null);
+			Assert ("t14", col[typeof(DescriptionAttribute)] != null);
+			DesignerAttribute attribute = col[typeof(DesignerAttribute)] as DesignerAttribute;
+			Assert ("t15", attribute != null);
+			AssertEquals ("t16", attribute.DesignerTypeName, typeof(MyOtherDesigner).AssemblyQualifiedName);
 		}
 		
 		[Test]