diff options
| author | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-20 20:33:05 -0500 |
|---|---|---|
| committer | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-20 20:33:05 -0500 |
| commit | 767cdc1f6f6a63ce997fc9476911e2c361f9d402 (patch) | |
| tree | 49add55976f895441167c66cfa95e5c7688d18ce /MediaBrowser.Model/Entities/IHasProviderIds.cs | |
| parent | 845554722efaed872948a9e0f7202e3ef52f1b6e (diff) | |
Pushing missing changes
Diffstat (limited to 'MediaBrowser.Model/Entities/IHasProviderIds.cs')
| -rw-r--r-- | MediaBrowser.Model/Entities/IHasProviderIds.cs | 151 |
1 files changed, 94 insertions, 57 deletions
diff --git a/MediaBrowser.Model/Entities/IHasProviderIds.cs b/MediaBrowser.Model/Entities/IHasProviderIds.cs index 96eb78f243..2ddf8ffad1 100644 --- a/MediaBrowser.Model/Entities/IHasProviderIds.cs +++ b/MediaBrowser.Model/Entities/IHasProviderIds.cs @@ -1,57 +1,94 @@ -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 ProviderIdsExtensions
- {
- /// <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);
- }
- }
-}
+using System; +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 + { + /// <summary> + /// Gets or sets the provider ids. + /// </summary> + /// <value>The provider ids.</value> + Dictionary<string, string> ProviderIds { get; set; } + } + + /// <summary> + /// Class ProviderIdsExtensions + /// </summary> + public static class ProviderIdsExtensions + { + /// <summary> + /// Gets a provider id + /// </summary> + /// <param name="instance">The instance.</param> + /// <param name="provider">The provider.</param> + /// <returns>System.String.</returns> + public static string GetProviderId(this IHasProviderIds instance, MetadataProviders provider) + { + return instance.GetProviderId(provider.ToString()); + } + + /// <summary> + /// Gets a provider id + /// </summary> + /// <param name="instance">The instance.</param> + /// <param name="name">The name.</param> + /// <returns>System.String.</returns> + public static string GetProviderId(this IHasProviderIds instance, string name) + { + if (instance.ProviderIds == null) + { + return null; + } + + string id; + instance.ProviderIds.TryGetValue(name, out id); + return id; + } + + /// <summary> + /// Sets a provider id + /// </summary> + /// <param name="instance">The instance.</param> + /// <param name="name">The name.</param> + /// <param name="value">The value.</param> + public static void SetProviderId(this IHasProviderIds instance, string name, string value) + { + // If it's null remove the key from the dictionary + if (string.IsNullOrEmpty(value)) + { + if (instance.ProviderIds != null) + { + if (instance.ProviderIds.ContainsKey(name)) + { + instance.ProviderIds.Remove(name); + } + } + } + else + { + // Ensure it exists + if (instance.ProviderIds == null) + { + instance.ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); + } + + instance.ProviderIds[name] = value; + } + } + + /// <summary> + /// Sets a provider id + /// </summary> + /// <param name="instance">The instance.</param> + /// <param name="provider">The provider.</param> + /// <param name="value">The value.</param> + public static void SetProviderId(this IHasProviderIds instance, MetadataProviders provider, string value) + { + instance.SetProviderId(provider.ToString(), value); + } + } +} |
