aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Entities/IHasProviderIds.cs
blob: 8b9852dda3c3d89c493601fe7bda1afc66950c6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Collections.Generic;

namespace MediaBrowser.Model.Entities
{
    /// <summary>
    /// Since BaseItem and DTOBaseItem both have ProviderIds, this interface helps avoid code repition by using extension methods
    /// </summary>
    public interface IHasProviderIds
    {
        Dictionary<string, string> ProviderIds { get; set; }
    }

    public static class IProviderIdsExtensions
    {
        /// <summary>
        /// Gets a provider id
        /// </summary>
        public static string GetProviderId(this IHasProviderIds instance, MetadataProviders provider)
        {
            return instance.GetProviderId(provider.ToString());
        }

        /// <summary>
        /// Gets a provider id
        /// </summary>
        public static string GetProviderId(this IHasProviderIds instance, string name)
        {
            if (instance.ProviderIds == null)
            {
                return null;
            }

            return instance.ProviderIds[name];
        }

        /// <summary>
        /// Sets a provider id
        /// </summary>
        public static void SetProviderId(this IHasProviderIds instance, string name, string value)
        {
            if (instance.ProviderIds == null)
            {
                instance.ProviderIds = new Dictionary<string, string>();
            }

            instance.ProviderIds[name] = value;
        }

        /// <summary>
        /// Sets a provider id
        /// </summary>
        public static void SetProviderId(this IHasProviderIds instance, MetadataProviders provider, string value)
        {
            instance.SetProviderId(provider.ToString(), value);
        }
    }
}