using System.Collections.Generic; namespace Jellyfin.Extensions { /// /// Static extensions for the interface. /// public static class DictionaryExtensions { /// /// Gets a string from a string dictionary, checking all keys sequentially, /// stopping at the first key that returns a result that's neither null nor blank. /// /// The dictionary. /// The first checked key. /// System.String. public static string? GetFirstNotNullNorWhiteSpaceValue(this IReadOnlyDictionary dictionary, string key1) { return dictionary.GetFirstNotNullNorWhiteSpaceValue(key1, string.Empty, string.Empty); } /// /// Gets a string from a string dictionary, checking all keys sequentially, /// stopping at the first key that returns a result that's neither null nor blank. /// /// The dictionary. /// The first checked key. /// The second checked key. /// System.String. public static string? GetFirstNotNullNorWhiteSpaceValue(this IReadOnlyDictionary dictionary, string key1, string key2) { return dictionary.GetFirstNotNullNorWhiteSpaceValue(key1, key2, string.Empty); } /// /// Gets a string from a string dictionary, checking all keys sequentially, /// stopping at the first key that returns a result that's neither null nor blank. /// /// The dictionary. /// The first checked key. /// The second checked key. /// The third checked key. /// System.String. public static string? GetFirstNotNullNorWhiteSpaceValue(this IReadOnlyDictionary dictionary, string key1, string key2, string key3) { if (dictionary.TryGetValue(key1, out var val) && !string.IsNullOrWhiteSpace(val)) { return val; } if (!string.IsNullOrEmpty(key2) && dictionary.TryGetValue(key2, out val) && !string.IsNullOrWhiteSpace(val)) { return val; } if (!string.IsNullOrEmpty(key3) && dictionary.TryGetValue(key3, out val) && !string.IsNullOrWhiteSpace(val)) { return val; } return null; } } }