< Summary - Jellyfin

Information
Class: Jellyfin.Extensions.DictionaryExtensions
Assembly: Jellyfin.Extensions
File(s): /srv/git/jellyfin/src/Jellyfin.Extensions/DictionaryExtensions.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 64
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetFirstNotNullNorWhiteSpaceValue(...)100%11100%
GetFirstNotNullNorWhiteSpaceValue(...)100%11100%
GetFirstNotNullNorWhiteSpaceValue(...)100%1616100%

File(s)

/srv/git/jellyfin/src/Jellyfin.Extensions/DictionaryExtensions.cs

#LineLine coverage
 1using System.Collections.Generic;
 2
 3namespace Jellyfin.Extensions
 4{
 5    /// <summary>
 6    /// Static extensions for the <see cref="IReadOnlyDictionary{TKey,TValue}"/> interface.
 7    /// </summary>
 8    public static class DictionaryExtensions
 9    {
 10        /// <summary>
 11        /// Gets a string from a string dictionary, checking all keys sequentially,
 12        /// stopping at the first key that returns a result that's neither null nor blank.
 13        /// </summary>
 14        /// <param name="dictionary">The dictionary.</param>
 15        /// <param name="key1">The first checked key.</param>
 16        /// <returns>System.String.</returns>
 17        public static string? GetFirstNotNullNorWhiteSpaceValue(this IReadOnlyDictionary<string, string> dictionary, str
 18        {
 2419            return dictionary.GetFirstNotNullNorWhiteSpaceValue(key1, string.Empty, string.Empty);
 20        }
 21
 22        /// <summary>
 23        /// Gets a string from a string dictionary, checking all keys sequentially,
 24        /// stopping at the first key that returns a result that's neither null nor blank.
 25        /// </summary>
 26        /// <param name="dictionary">The dictionary.</param>
 27        /// <param name="key1">The first checked key.</param>
 28        /// <param name="key2">The second checked key.</param>
 29        /// <returns>System.String.</returns>
 30        public static string? GetFirstNotNullNorWhiteSpaceValue(this IReadOnlyDictionary<string, string> dictionary, str
 31        {
 1032            return dictionary.GetFirstNotNullNorWhiteSpaceValue(key1, key2, string.Empty);
 33        }
 34
 35        /// <summary>
 36        /// Gets a string from a string dictionary, checking all keys sequentially,
 37        /// stopping at the first key that returns a result that's neither null nor blank.
 38        /// </summary>
 39        /// <param name="dictionary">The dictionary.</param>
 40        /// <param name="key1">The first checked key.</param>
 41        /// <param name="key2">The second checked key.</param>
 42        /// <param name="key3">The third checked key.</param>
 43        /// <returns>System.String.</returns>
 44        public static string? GetFirstNotNullNorWhiteSpaceValue(this IReadOnlyDictionary<string, string> dictionary, str
 45        {
 5646            if (dictionary.TryGetValue(key1, out var val) && !string.IsNullOrWhiteSpace(val))
 47            {
 448                return val;
 49            }
 50
 5251            if (!string.IsNullOrEmpty(key2) && dictionary.TryGetValue(key2, out val) && !string.IsNullOrWhiteSpace(val))
 52            {
 253                return val;
 54            }
 55
 5056            if (!string.IsNullOrEmpty(key3) && dictionary.TryGetValue(key3, out val) && !string.IsNullOrWhiteSpace(val))
 57            {
 358                return val;
 59            }
 60
 4761            return null;
 62        }
 63    }
 64}