IHasProviderIds.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  2. namespace MediaBrowser.Model.Entities
  3. {
  4. /// <summary>
  5. /// Since BaseItem and DTOBaseItem both have ProviderIds, this interface helps avoid code repition by using extension methods
  6. /// </summary>
  7. public interface IHasProviderIds
  8. {
  9. Dictionary<string, string> ProviderIds { get; set; }
  10. }
  11. public static class ProviderIdsExtensions
  12. {
  13. /// <summary>
  14. /// Gets a provider id
  15. /// </summary>
  16. public static string GetProviderId(this IHasProviderIds instance, MetadataProviders provider)
  17. {
  18. return instance.GetProviderId(provider.ToString());
  19. }
  20. /// <summary>
  21. /// Gets a provider id
  22. /// </summary>
  23. public static string GetProviderId(this IHasProviderIds instance, string name)
  24. {
  25. if (instance.ProviderIds == null)
  26. {
  27. return null;
  28. }
  29. return instance.ProviderIds[name];
  30. }
  31. /// <summary>
  32. /// Sets a provider id
  33. /// </summary>
  34. public static void SetProviderId(this IHasProviderIds instance, string name, string value)
  35. {
  36. if (instance.ProviderIds == null)
  37. {
  38. instance.ProviderIds = new Dictionary<string, string>();
  39. }
  40. instance.ProviderIds[name] = value;
  41. }
  42. /// <summary>
  43. /// Sets a provider id
  44. /// </summary>
  45. public static void SetProviderId(this IHasProviderIds instance, MetadataProviders provider, string value)
  46. {
  47. instance.SetProviderId(provider.ToString(), value);
  48. }
  49. }
  50. }