StringComparer.cs 855 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. namespace UnityTest
  3. {
  4. public class StringComparer : ComparerBaseGeneric<string>
  5. {
  6. public enum CompareType
  7. {
  8. Equal,
  9. NotEqual,
  10. Shorter,
  11. Longer
  12. }
  13. public CompareType compareType;
  14. public StringComparison comparisonType = StringComparison.Ordinal;
  15. public bool ignoreCase = false;
  16. protected override bool Compare (string a, string b)
  17. {
  18. if (ignoreCase)
  19. {
  20. a = a.ToLower ();
  21. b = b.ToLower ();
  22. }
  23. switch (compareType)
  24. {
  25. case CompareType.Equal:
  26. return String.Compare(a, b, comparisonType) == 0;
  27. case CompareType.NotEqual:
  28. return String.Compare(a, b, comparisonType) != 0;
  29. case CompareType.Longer:
  30. return String.Compare(a, b, comparisonType) > 0;
  31. case CompareType.Shorter:
  32. return String.Compare(a, b, comparisonType) < 0;
  33. }
  34. throw new Exception ();
  35. }
  36. }
  37. }