LinkedChild.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.Serialization;
  4. namespace MediaBrowser.Controller.Entities
  5. {
  6. public class LinkedChild
  7. {
  8. public string Path { get; set; }
  9. public LinkedChildType Type { get; set; }
  10. public string ItemName { get; set; }
  11. public string ItemType { get; set; }
  12. public int? ItemYear { get; set; }
  13. [IgnoreDataMember]
  14. public string Id { get; set; }
  15. /// <summary>
  16. /// Serves as a cache
  17. /// </summary>
  18. [IgnoreDataMember]
  19. public Guid? ItemId { get; set; }
  20. public static LinkedChild Create(BaseItem item)
  21. {
  22. return new LinkedChild
  23. {
  24. Path = item.Path,
  25. Type = LinkedChildType.Manual
  26. };
  27. }
  28. public LinkedChild()
  29. {
  30. Id = Guid.NewGuid().ToString("N");
  31. }
  32. }
  33. public enum LinkedChildType
  34. {
  35. Manual = 0,
  36. Shortcut = 1
  37. }
  38. public class LinkedChildComparer : IEqualityComparer<LinkedChild>
  39. {
  40. public bool Equals(LinkedChild x, LinkedChild y)
  41. {
  42. if (x.Type == y.Type)
  43. {
  44. return string.Equals(x.Path, y.Path, StringComparison.OrdinalIgnoreCase);
  45. }
  46. return false;
  47. }
  48. public int GetHashCode(LinkedChild obj)
  49. {
  50. return (obj.Path + obj.Type).GetHashCode();
  51. }
  52. }
  53. }