Sfoglia il codice sorgente

2006-05-22 Atsushi Enomoto <[email protected]>

	* TypeDescriptor.cs : GetProperties() does not return indexers.

	* TypeDescriptorTest.cs : added GetPropertiesIgnoreIndexers().


svn path=/trunk/mcs/; revision=60947
Atsushi Eno 19 anni fa
parent
commit
e37046098b

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

@@ -1,3 +1,7 @@
+2006-05-22  Atsushi Enomoto  <[email protected]>
+
+	* TypeDescriptor.cs : GetProperties() does not return indexers.
+
 2006-05-11  Atsushi Enomoto  <[email protected]>
 
 	* ReflectionPropertyDescriptor.cs,

+ 4 - 3
mcs/class/System/System.ComponentModel/TypeDescriptor.cs

@@ -817,11 +817,12 @@ public sealed class TypeDescriptor
 				return _properties;
 			
 			PropertyInfo[] props = InfoType.GetProperties (BindingFlags.Instance | BindingFlags.Public);
-			PropertyDescriptor[] descs = new PropertyDescriptor [props.Length];
+			ArrayList descs = new ArrayList (props.Length);
 			for (int n=0; n<props.Length; n++)
-				descs [n] = new ReflectionPropertyDescriptor (props[n]);
+				if (props [n].GetIndexParameters ().Length == 0)
+					descs.Add (new ReflectionPropertyDescriptor (props[n]));
 
-			_properties = new PropertyDescriptorCollection (descs, true);
+			_properties = new PropertyDescriptorCollection ((PropertyDescriptor[]) descs.ToArray (typeof (PropertyDescriptor)), true);
 			return _properties;
 		}
 	}

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

@@ -1,3 +1,7 @@
+2006-05-22  Atsushi Enomoto  <[email protected]>
+
+	* TypeDescriptorTest.cs : added GetPropertiesIgnoreIndexers().
+
 2006-04-25  Atsushi Enomoto  <[email protected]>
 
 	* ByteConverterTests.cs,

+ 15 - 0
mcs/class/System/Test/System.ComponentModel/TypeDescriptorTests.cs

@@ -502,6 +502,21 @@ namespace MonoTests.System.ComponentModel
 			TestConverter converter = (TestConverter) t;
 			AssertEquals ("#03", typeof (TestConverterClass), converter.Type);
 		}
+
+		[Test]
+		public void GetPropertiesIgnoreIndexers ()
+		{
+			PropertyDescriptorCollection pc =
+				TypeDescriptor.GetProperties (typeof (string));
+			// There are two string properties: Length and Chars.
+			// Chars is an indexer.
+			//
+			// Future version of CLI might contain some additional
+			// properties. In that case simply increase the
+			// number. (Also, it is fine to just remove #2.)
+			AssertEquals ("#1", 1, pc.Count);
+			AssertEquals ("#2", "Length", pc [0].Name);
+		}
 	}
 }