/// <summary>Returns a hash code for the given object, using a hashing algorithm that ignores the case of strings.</summary> /// <returns>A hash code for the given object, using a hashing algorithm that ignores the case of strings.</returns> /// <param name="obj">The <see cref="T:System.Object" /> for which a hash code is to be returned. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="obj" /> is null. </exception> /// <filterpriority>2</filterpriority> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /> /// </PermissionSet> public int GetHashCode(object obj) { if (obj == null) { throw new ArgumentNullException("obj"); } string text = obj as string; if (text == null) { return(obj.GetHashCode()); } int num = 0; if (this.m_text != null && !CaseInsensitiveHashCodeProvider.AreEqual(this.m_text, CultureInfo.InvariantCulture)) { foreach (char c in this.m_text.ToLower(text)) { num = num * 31 + (int)c; } } else { for (int j = 0; j < text.Length; j++) { char c = char.ToLower(text[j], CultureInfo.InvariantCulture); num = num * 31 + (int)c; } } return(num); }
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.CaseInsensitiveHashCodeProvider" /> class using the <see cref="P:System.Threading.Thread.CurrentCulture" /> of the current thread.</summary> public CaseInsensitiveHashCodeProvider() { CultureInfo currentCulture = CultureInfo.CurrentCulture; if (!CaseInsensitiveHashCodeProvider.AreEqual(currentCulture, CultureInfo.InvariantCulture)) { this.m_text = CultureInfo.CurrentCulture.TextInfo; } }
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.CaseInsensitiveHashCodeProvider" /> class using the specified <see cref="T:System.Globalization.CultureInfo" />.</summary> /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use for the new <see cref="T:System.Collections.CaseInsensitiveHashCodeProvider" />. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="culture" /> is null. </exception> public CaseInsensitiveHashCodeProvider(CultureInfo culture) { if (culture == null) { throw new ArgumentNullException("culture"); } if (!CaseInsensitiveHashCodeProvider.AreEqual(culture, CultureInfo.InvariantCulture)) { this.m_text = culture.TextInfo; } }