2 // System.Collections.CaseInsensitiveHashCodeProvider.cs
5 // Sergey Chaban (serge@wildwestsoftware.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 using System.Globalization;
11 namespace System.Collections
14 public class CaseInsensitiveHashCodeProvider : IHashCodeProvider
16 static readonly CaseInsensitiveHashCodeProvider singleton = new CaseInsensitiveHashCodeProvider ();
17 static readonly CaseInsensitiveHashCodeProvider singletonInvariant = new CaseInsensitiveHashCodeProvider (true);
21 // Public instance constructor
22 public CaseInsensitiveHashCodeProvider ()
24 culture = CultureInfo.CurrentCulture;
27 private CaseInsensitiveHashCodeProvider (bool invariant)
29 // leave culture == null
32 public CaseInsensitiveHashCodeProvider (CultureInfo culture)
35 throw new ArgumentNullException ("culture");
36 if (culture.LCID != CultureInfo.InvariantCulture.LCID)
37 this.culture = culture;
38 // else leave culture == null
42 // Public static properties
45 public static CaseInsensitiveHashCodeProvider Default {
56 static CaseInsensitiveHashCodeProvider DefaultInvariant {
58 return singletonInvariant;
66 public int GetHashCode (object obj)
69 throw new ArgumentNullException ("obj");
71 string str = obj as string;
74 return obj.GetHashCode ();
79 if (culture != null) {
80 for (int i = 0; i < str.Length; i++) {
81 c = Char.ToLower (str [i], culture);
86 for (int i = 0; i < str.Length; i++) {
87 c = Char.ToLowerInvariant (str [i]);