2004-04-25 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
authorAndreas N <andreas@mono-cvs.ximian.com>
Sun, 25 Apr 2004 11:42:52 +0000 (11:42 -0000)
committerAndreas N <andreas@mono-cvs.ximian.com>
Sun, 25 Apr 2004 11:42:52 +0000 (11:42 -0000)
* CaseInsensitiveHashCodeProvider.cs: Fix the default constructor (needs to
  set CurrentCulture, Add null check to other constructor, Call correct function
  for invariant case, ensure culture is set to null for invariant case, removed
  static constructor, made invariant version available as internal in .Net 1.0

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

mcs/class/corlib/System.Collections/CaseInsensitiveHashCodeProvider.cs
mcs/class/corlib/System.Collections/ChangeLog

index dc790cba6926378103c8650162723f1a053b4013..5d6d7976af47e8d1f4bee8fe19417148ece53253 100644 (file)
@@ -16,31 +16,31 @@ namespace System.Collections {
        [Serializable]\r
        public class CaseInsensitiveHashCodeProvider : IHashCodeProvider {\r
 \r
-               private static CaseInsensitiveHashCodeProvider singleton;\r
-               private static CaseInsensitiveHashCodeProvider singletonInvariant;\r
+               private static CaseInsensitiveHashCodeProvider singleton = new CaseInsensitiveHashCodeProvider ();\r
+               private static CaseInsensitiveHashCodeProvider singletonInvariant = new CaseInsensitiveHashCodeProvider (true);\r
                \r
                CultureInfo culture;\r
 \r
-\r
-               // Class constructor\r
-\r
-               static CaseInsensitiveHashCodeProvider ()\r
-               {\r
-                       singleton = new CaseInsensitiveHashCodeProvider ();\r
-                       singletonInvariant = new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture);\r
-               }\r
-\r
-\r
-\r
                // Public instance constructor\r
 \r
                public CaseInsensitiveHashCodeProvider ()\r
-               {\r
+               {
+                       culture = CultureInfo.CurrentCulture;\r
+               }
+
+               public CaseInsensitiveHashCodeProvider (bool invariant)\r
+               {
+                       // leave culture == null\r
                }\r
 \r
                public CaseInsensitiveHashCodeProvider (CultureInfo culture)\r
-               {\r
-                       this.culture = culture;\r
+               {
+                       if (culture == null)
+                               throw new ArgumentNullException ("culture");
+
+                       if (culture.LCID != CultureInfo.InvariantCulture.LCID)\r
+                               this.culture = culture;
+                       // else leave culture == null\r
                }\r
 \r
 \r
@@ -55,13 +55,15 @@ namespace System.Collections {
                }\r
 \r
 #if NET_1_1\r
-               public static CaseInsensitiveHashCodeProvider DefaultInvariant {\r
+               public
+#else
+               internal
+#endif
+               static CaseInsensitiveHashCodeProvider DefaultInvariant {\r
                        get {\r
                                return singletonInvariant;\r
                        }\r
                }\r
-#endif\r
-\r
 \r
                //\r
                // Instance methods\r
@@ -73,9 +75,8 @@ namespace System.Collections {
 \r
                public int GetHashCode (object obj)\r
                {\r
-                       if (obj == null) {\r
-                               throw new ArgumentNullException ("obj is null");\r
-                       }\r
+                       if (obj == null)\r
+                               throw new ArgumentNullException ("obj");\r
 \r
                        string str = obj as string;\r
 \r
@@ -94,7 +95,7 @@ namespace System.Collections {
                        }\r
                        else {\r
                                for (int i = 0;i<length;i++) {\r
-                                       c = Char.ToLower (str [i]);\r
+                                       c = Char.ToLowerInvariant (str [i]);\r
                                        h = h * 31 + c;\r
                                }\r
                        }\r
index 9efae286cd6f1d482b7e17b67fe1ed61871cd45f..faf16978d2298e9201b5c57a74d5b543a3384144 100644 (file)
@@ -1,3 +1,10 @@
+2004-04-25  Andreas Nahr <ClassDevelopment@A-SoftTech.com>
+
+       * CaseInsensitiveHashCodeProvider.cs: Fix the default constructor (needs to
+         set CurrentCulture, Add null check to other constructor, Call correct function
+         for invariant case, ensure culture is set to null for invariant case, removed
+         static constructor, made invariant version available as internal in .Net 1.0
+
 2004-04-21  Lluis Sanchez Gual  <lluis@ximian.com>
 
        * CaseInsensitiveHashCodeProvider.cs: If the culture is null, don't use