CaseInsensitiveHashCodeProvider.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. [Serializable]
  11. public class CaseInsensitiveHashCodeProvider : IHashCodeProvider {
  12. private static CaseInsensitiveHashCodeProvider singleton;
  13. // Class constructor
  14. static CaseInsensitiveHashCodeProvider ()
  15. {
  16. singleton=new CaseInsensitiveHashCodeProvider ();
  17. }
  18. // Public instance constructor
  19. public CaseInsensitiveHashCodeProvider ()
  20. {
  21. }
  22. //
  23. // Public static properties
  24. //
  25. public static CaseInsensitiveHashCodeProvider Default {
  26. get {
  27. return singleton;
  28. }
  29. }
  30. //
  31. // Instance methods
  32. //
  33. //
  34. // IHashCodeProvider
  35. //
  36. [MonoTODO]
  37. public int GetHashCode (object obj)
  38. {
  39. if (obj == null) {
  40. throw new ArgumentNullException ("obj is null");
  41. }
  42. string str = obj as string;
  43. if (str == null) {
  44. // FIXME:
  45. return 0;
  46. }
  47. int h = 0;
  48. char c;
  49. if (str.Length > 0) {
  50. for (int i = 0;i<str.Length;i++) {
  51. c = str [i];
  52. if (Char.IsLetter (c))
  53. c = Char.ToLower (c);
  54. h = h * 31 + c;
  55. }
  56. }
  57. return h;
  58. }
  59. } // CaseInsensitiveHashCodeProvider
  60. }