GameSystemComparer.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Sorting;
  4. using MediaBrowser.Model.Querying;
  5. namespace Emby.Server.Implementations.Sorting
  6. {
  7. public class GameSystemComparer : IBaseItemComparer
  8. {
  9. /// <summary>
  10. /// Compares the specified x.
  11. /// </summary>
  12. /// <param name="x">The x.</param>
  13. /// <param name="y">The y.</param>
  14. /// <returns>System.Int32.</returns>
  15. public int Compare(BaseItem x, BaseItem y)
  16. {
  17. return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);
  18. }
  19. /// <summary>
  20. /// Gets the value.
  21. /// </summary>
  22. /// <param name="x">The x.</param>
  23. /// <returns>System.String.</returns>
  24. private static string GetValue(BaseItem x)
  25. {
  26. var game = x as Game;
  27. if (game != null)
  28. {
  29. return game.GameSystem;
  30. }
  31. var system = x as GameSystem;
  32. if (system != null)
  33. {
  34. return system.GameSystemName;
  35. }
  36. return string.Empty;
  37. }
  38. /// <summary>
  39. /// Gets the name.
  40. /// </summary>
  41. /// <value>The name.</value>
  42. public string Name => ItemSortBy.GameSystem;
  43. }
  44. }