AlbumComparer.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Entities.Audio;
  4. using MediaBrowser.Controller.Sorting;
  5. using MediaBrowser.Model.Querying;
  6. namespace Emby.Server.Implementations.Sorting
  7. {
  8. /// <summary>
  9. /// Class AlbumComparer.
  10. /// </summary>
  11. public class AlbumComparer : IBaseItemComparer
  12. {
  13. /// <summary>
  14. /// Gets the name.
  15. /// </summary>
  16. /// <value>The name.</value>
  17. public string Name => ItemSortBy.Album;
  18. /// <summary>
  19. /// Compares the specified x.
  20. /// </summary>
  21. /// <param name="x">The x.</param>
  22. /// <param name="y">The y.</param>
  23. /// <returns>System.Int32.</returns>
  24. public int Compare(BaseItem? x, BaseItem? y)
  25. {
  26. return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);
  27. }
  28. /// <summary>
  29. /// Gets the value.
  30. /// </summary>
  31. /// <param name="x">The x.</param>
  32. /// <returns>System.String.</returns>
  33. private static string GetValue(BaseItem? x)
  34. {
  35. return x is Audio audio ? audio.Album : string.Empty;
  36. }
  37. }
  38. }