LinkedChild.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. [IgnoreDataMember]
  13. public string Id { get; set; }
  14. /// <summary>
  15. /// Serves as a cache
  16. /// </summary>
  17. public Guid? ItemId { get; set; }
  18. public static LinkedChild Create(BaseItem item)
  19. {
  20. return new LinkedChild
  21. {
  22. Path = item.Path,
  23. Type = LinkedChildType.Manual
  24. };
  25. }
  26. public LinkedChild()
  27. {
  28. Id = Guid.NewGuid().ToString("N");
  29. }
  30. }
  31. public enum LinkedChildType
  32. {
  33. Manual = 0,
  34. Shortcut = 1
  35. }
  36. public class LinkedChildComparer : IEqualityComparer<LinkedChild>
  37. {
  38. public bool Equals(LinkedChild x, LinkedChild y)
  39. {
  40. if (x.Type == y.Type)
  41. {
  42. return string.Equals(x.Path, y.Path, StringComparison.OrdinalIgnoreCase);
  43. }
  44. return false;
  45. }
  46. public int GetHashCode(LinkedChild obj)
  47. {
  48. return (obj.Path + obj.Type).GetHashCode();
  49. }
  50. }
  51. }