2008-03-05 09:52:00 -05:00
|
|
|
// ==++==
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// ==--==
|
2008-11-17 18:29:00 -05:00
|
|
|
//============================================================
|
|
|
|
//
|
|
|
|
// Class: CaseInsensitiveHashCodeProvider
|
|
|
|
//
|
|
|
|
// Purpose: Designed to support hashtables which require
|
|
|
|
// case-insensitive behavior while still maintaining case,
|
|
|
|
// this provides an efficient mechanism for getting the
|
|
|
|
// hashcode of the string ignoring case.
|
|
|
|
//
|
|
|
|
//============================================================
|
|
|
|
namespace System.Collections
|
|
|
|
{
|
2008-03-05 09:52:00 -05:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
//| <include path='docs/doc[@for="CaseInsensitiveHashCodeProvider"]/*' />
|
|
|
|
public class CaseInsensitiveHashCodeProvider : IHashCodeProvider {
|
|
|
|
|
|
|
|
public static readonly CaseInsensitiveHashCodeProvider Default
|
|
|
|
= new CaseInsensitiveHashCodeProvider();
|
|
|
|
|
|
|
|
//| <include path='docs/doc[@for="CaseInsensitiveHashCodeProvider.CaseInsensitiveHashCodeProvider"]/*' />
|
|
|
|
public CaseInsensitiveHashCodeProvider() {
|
|
|
|
}
|
|
|
|
|
|
|
|
//| <include path='docs/doc[@for="CaseInsensitiveHashCodeProvider.DefaultInvariant"]/*' />
|
|
|
|
public static CaseInsensitiveHashCodeProvider DefaultInvariant
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return Default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//| <include path='docs/doc[@for="CaseInsensitiveHashCodeProvider.GetHashCode"]/*' />
|
|
|
|
public int GetHashCode(Object obj) {
|
2008-11-17 18:29:00 -05:00
|
|
|
if (obj == null) {
|
2008-03-05 09:52:00 -05:00
|
|
|
throw new ArgumentNullException("obj");
|
|
|
|
}
|
|
|
|
|
|
|
|
String s = obj as String;
|
2008-11-17 18:29:00 -05:00
|
|
|
if (s == null) {
|
2008-03-05 09:52:00 -05:00
|
|
|
return obj.GetHashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return TextInfo.GetCaseInsensitiveHashCode(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|