diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2021-02-22 20:59:57 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-22 20:59:57 -0500 |
| commit | 5ce4df4178719d48f6071e5d42a80f95da3fcf76 (patch) | |
| tree | bf6bbda6cca09f76ea1ac074f56dbe1d06edc16a /MediaBrowser.Model/Entities | |
| parent | 23ff1fab46d13d24203748a4054f055a76aae233 (diff) | |
| parent | 2b131ddaac922eb7bb9f154afbb3ff2d283cbf0f (diff) | |
Merge pull request #5270 from Bond-009/imdb
Diffstat (limited to 'MediaBrowser.Model/Entities')
| -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 { |
