AlbumComparer.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /// Compares the specified x.
  15. /// </summary>
  16. /// <param name="x">The x.</param>
  17. /// <param name="y">The y.</param>
  18. /// <returns>System.Int32.</returns>
  19. public int Compare(BaseItem? x, BaseItem? y)
  20. {
  21. return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);
  22. }
  23. /// <summary>
  24. /// Gets the value.
  25. /// </summary>
  26. /// <param name="x">The x.</param>
  27. /// <returns>System.String.</returns>
  28. private static string? GetValue(BaseItem? x)
  29. {
  30. var audio = x as Audio;
  31. return audio == null ? string.Empty : audio.Album;
  32. }
  33. /// <summary>
  34. /// Gets the name.
  35. /// </summary>
  36. /// <value>The name.</value>
  37. public string Name => ItemSortBy.Album;
  38. }
  39. }