SortExtensions.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. namespace MediaBrowser.Controller.Sorting
  7. {
  8. public static class SortExtensions
  9. {
  10. private static readonly AlphanumComparator _comparer = new AlphanumComparator();
  11. public static IEnumerable<T> OrderByString<T>(this IEnumerable<T> list, Func<T, string> getName)
  12. {
  13. return list.OrderBy(getName, _comparer);
  14. }
  15. public static IEnumerable<T> OrderByStringDescending<T>(this IEnumerable<T> list, Func<T, string> getName)
  16. {
  17. return list.OrderByDescending(getName, _comparer);
  18. }
  19. public static IOrderedEnumerable<T> ThenByString<T>(this IOrderedEnumerable<T> list, Func<T, string> getName)
  20. {
  21. return list.ThenBy(getName, _comparer);
  22. }
  23. public static IOrderedEnumerable<T> ThenByStringDescending<T>(this IOrderedEnumerable<T> list, Func<T, string> getName)
  24. {
  25. return list.ThenByDescending(getName, _comparer);
  26. }
  27. }
  28. }