diff options
Diffstat (limited to 'MediaBrowser.Model/Entities/ProviderIdsExtensions.cs')
| -rw-r--r-- | MediaBrowser.Model/Entities/ProviderIdsExtensions.cs | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs index 98097477c..4aff6e3a4 100644 --- a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs +++ b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace MediaBrowser.Model.Entities { @@ -9,14 +10,26 @@ namespace MediaBrowser.Model.Entities public static class ProviderIdsExtensions { /// <summary> - /// Determines whether [has provider identifier] [the specified instance]. + /// Gets a provider id. /// </summary> /// <param name="instance">The instance.</param> - /// <param name="provider">The provider.</param> - /// <returns><c>true</c> if [has provider identifier] [the specified instance]; otherwise, <c>false</c>.</returns> - public static bool HasProviderId(this IHasProviderIds instance, MetadataProvider provider) + /// <param name="name">The name.</param> + /// <param name="id">The provider id.</param> + /// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns> + public static bool TryGetProviderId(this IHasProviderIds instance, string name, [MaybeNullWhen(false)] out string id) { - return !string.IsNullOrEmpty(instance.GetProviderId(provider.ToString())); + if (instance == null) + { + throw new ArgumentNullException(nameof(instance)); + } + + if (instance.ProviderIds == null) + { + id = null; + return false; + } + + return instance.ProviderIds.TryGetValue(name, out id); } /// <summary> @@ -24,10 +37,11 @@ namespace MediaBrowser.Model.Entities /// </summary> /// <param name="instance">The instance.</param> /// <param name="provider">The provider.</param> - /// <returns>System.String.</returns> - public static string? GetProviderId(this IHasProviderIds instance, MetadataProvider provider) + /// <param name="id">The provider id.</param> + /// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns> + public static bool TryGetProviderId(this IHasProviderIds instance, MetadataProvider provider, [MaybeNullWhen(false)] out string id) { - return instance.GetProviderId(provider.ToString()); + return instance.TryGetProviderId(provider.ToString(), out id); } /// <summary> @@ -38,18 +52,19 @@ namespace MediaBrowser.Model.Entities /// <returns>System.String.</returns> public static string? GetProviderId(this IHasProviderIds instance, string name) { - if (instance == null) - { - throw new ArgumentNullException(nameof(instance)); - } - - if (instance.ProviderIds == null) - { - return null; - } + instance.TryGetProviderId(name, out string? id); + return id; + } - instance.ProviderIds.TryGetValue(name, out string? id); - return string.IsNullOrEmpty(id) ? null : id; + /// <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, MetadataProvider provider) + { + return instance.GetProviderId(provider.ToString()); } /// <summary> @@ -68,13 +83,7 @@ namespace MediaBrowser.Model.Entities // 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); - } - } + instance.ProviderIds?.Remove(name); } else { |
