LinkedChild.cs 1.3 KB

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