NameExtensions.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using MediaBrowser.Common.Extensions;
  2. using MoreLinq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. namespace MediaBrowser.Controller.Library
  7. {
  8. public static class NameExtensions
  9. {
  10. public static bool AreEqual(string name1, string name2)
  11. {
  12. name1 = NormalizeForComparison(name1);
  13. name2 = NormalizeForComparison(name2);
  14. return string.Equals(name1, name2, StringComparison.OrdinalIgnoreCase);
  15. }
  16. public static bool EqualsAny(IEnumerable<string> names, string name)
  17. {
  18. name = NormalizeForComparison(name);
  19. return names.Any(i => string.Equals(NormalizeForComparison(i), name, StringComparison.OrdinalIgnoreCase));
  20. }
  21. private static string NormalizeForComparison(string name)
  22. {
  23. if (string.IsNullOrWhiteSpace(name))
  24. {
  25. return string.Empty;
  26. }
  27. return name.RemoveDiacritics();
  28. }
  29. public static IEnumerable<string> DistinctNames(this IEnumerable<string> names)
  30. {
  31. return names.DistinctBy(NormalizeForComparison, StringComparer.OrdinalIgnoreCase);
  32. }
  33. }
  34. }