ArtistComparer.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Entities.Audio;
  3. using MediaBrowser.Controller.Sorting;
  4. using MediaBrowser.Model.Querying;
  5. using System;
  6. using System.Linq;
  7. namespace MediaBrowser.Server.Implementations.Sorting
  8. {
  9. /// <summary>
  10. /// Class ArtistComparer
  11. /// </summary>
  12. public class ArtistComparer : 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 string GetValue(BaseItem x)
  30. {
  31. var audio = x as Audio;
  32. if (audio == null)
  33. {
  34. return string.Empty;
  35. }
  36. return audio.Artist ?? string.Empty;
  37. }
  38. /// <summary>
  39. /// Gets the name.
  40. /// </summary>
  41. /// <value>The name.</value>
  42. public string Name
  43. {
  44. get { return ItemSortBy.Artist; }
  45. }
  46. }
  47. }