Kaynağa Gözat

* PropertyDescriptorCollection.cs: optimized Find method, removed culture sensitive string comparison
* PropertyDescriptorCollectionTests.cs: added test for Find method

svn path=/trunk/mcs/; revision=91873

Vladimir Krasnov 18 yıl önce
ebeveyn
işleme
697eb249dc

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

@@ -1,3 +1,8 @@
+2007-12-25  Vladimir Krasnov  <[email protected]>
+
+	* PropertyDescriptorCollection.cs: optimized Find method, removed
+	culture sensitive string comparison
+
 2007-12-19  Dick Porter  <[email protected]>
 
 	* Win32Exception.cs: Add text for error 5, Access denied.

+ 20 - 2
mcs/class/System/System.ComponentModel/PropertyDescriptorCollection.cs

@@ -144,8 +144,26 @@ namespace System.ComponentModel
 			}
 
 			foreach (PropertyDescriptor p in properties) {
-				if (0 == String.Compare (name, p.Name, ignoreCase, System.Globalization.CultureInfo.InvariantCulture))
-					return p;
+#if NET_2_0
+				if (ignoreCase) {
+					if (0 == String.Compare (name, p.Name, StringComparison.OrdinalIgnoreCase))
+						return p;
+				}
+				else {
+					if (0 == String.Compare (name, p.Name, StringComparison.Ordinal))
+						return p;
+				}
+#else
+				if (ignoreCase) {
+					if (0 == String.CompareOrdinal (name.ToLower (System.Globalization.CultureInfo.InvariantCulture),
+						p.Name.ToLower (System.Globalization.CultureInfo.InvariantCulture)))
+						return p;
+				}
+				else {
+					if (0 == String.CompareOrdinal (name, p.Name))
+						return p;
+				}
+#endif
 			}
 			return null;
 		}

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

@@ -1,3 +1,7 @@
+2007-12-25  Vladimir Krasnov  <[email protected]>
+
+	* PropertyDescriptorCollectionTests.cs: added test for Find method
+
 2007-12-04  Gert Driesen  <[email protected]>
 
 	* Win32ExceptionTest.cs: Added ctor tests.

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

@@ -118,6 +118,21 @@ namespace MonoTests.System.ComponentModel
 			dictionary.Add ("whatever", 5);
 		}
 
+		[Test]
+		public void CultureInsensitiveFindTest ()
+		{
+			Assert.AreEqual(0, string.Compare ("\u0061\u030a", "\u00e5", true), "#1");
+
+			PropertyDescriptorCollection col =
+				new PropertyDescriptorCollection (
+				new PropertyDescriptor [] {
+					new MockPropertyDescriptor ("hehe_\u0061\u030a", null),
+					new MockPropertyDescriptor ("heh_\u00e5", null) });
+
+			Assert.IsNull (col.Find ("heh_\u0061\u030a", false), "#2");
+			Assert.IsNull (col.Find ("hehe_\u00e5", false), "#3");
+
+		}
 #if NET_2_0
 		public void ReadOnly ()
 		{