CaseInsensitiveHashCodeProvider.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // System.Collections.CaseInsensitiveHashCodeProvider
  3. //
  4. // Author:
  5. // Sergey Chaban ([email protected])
  6. //
  7. using System;
  8. using System.Collections;
  9. namespace System.Collections {
  10. public class CaseInsensitiveHashCodeProvider : IHashCodeProvider {
  11. private static CaseInsensitiveHashCodeProvider singleton;
  12. // Class constructor
  13. static CaseInsensitiveHashCodeProvider ()
  14. {
  15. singleton=new CaseInsensitiveHashCodeProvider ();
  16. }
  17. // Public instance constructor
  18. public CaseInsensitiveHashCodeProvider ()
  19. {
  20. }
  21. //
  22. // Public static properties
  23. //
  24. public static CaseInsensitiveHashCodeProvider Default {
  25. get {
  26. return singleton;
  27. }
  28. }
  29. //
  30. // Instance methods
  31. //
  32. public override string ToString ()
  33. {
  34. return "mono::System.Collections.CaseInsensitiveHashCodeProvider";
  35. }
  36. //
  37. // IHashCodeProvider
  38. //
  39. [MonoTODO]
  40. public virtual int GetHashCode (object obj)
  41. {
  42. if (obj == null) {
  43. throw new ArgumentNullException ("obj is null");
  44. }
  45. string str = obj as string;
  46. if (str == null) {
  47. // FIXME:
  48. return 0;
  49. }
  50. int h = 0;
  51. char c;
  52. if (str.Length > 0) {
  53. for (int i = 0;i<str.Length;i++) {
  54. c = str [i];
  55. if (Char.IsLetter (c))
  56. c = Char.ToLower (c);
  57. h = h * 31 + c;
  58. }
  59. }
  60. return h;
  61. }
  62. } // CaseInsensitiveHashCodeProvider
  63. }