CaseInsensitiveComparer.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // System.Collections.CaseInsensitiveComparer
  3. //
  4. // Author:
  5. // Sergey Chaban ([email protected])
  6. //
  7. using System;
  8. using System.Collections;
  9. namespace System.Collections {
  10. public class CaseInsensitiveComparer : IComparer {
  11. private static CaseInsensitiveComparer singleton;
  12. // Class constructor
  13. static CaseInsensitiveComparer ()
  14. {
  15. singleton=new CaseInsensitiveComparer ();
  16. }
  17. // Public instance constructor
  18. public CaseInsensitiveComparer ()
  19. {
  20. }
  21. //
  22. // Public static properties
  23. //
  24. public static CaseInsensitiveComparer Default {
  25. get {
  26. return singleton;
  27. }
  28. }
  29. //
  30. // Instance methods
  31. //
  32. public override string ToString ()
  33. {
  34. return "mono::System.Collections.CaseInsensitiveComparer";
  35. }
  36. //
  37. // IComparer
  38. //
  39. public int Compare (object a, object b)
  40. {
  41. string str1 = a as string;
  42. string str2 = b as string;
  43. int res = 0;
  44. if (str1 != null && str2 != null) {
  45. res = String.Compare (str1, str2, true);
  46. }
  47. return res;
  48. }
  49. } // CaseInsensitiveComparer
  50. }