AlbumArtistComparer.cs 1.2 KB

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