CaseInsensitiveComparer.cs 1.2 KB

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