| | | 1 | | using System.Collections.Generic; |
| | | 2 | | |
| | | 3 | | namespace 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 | | /// <param name="key2">The second checked key.</param> |
| | | 17 | | /// <param name="key3">The third checked key.</param> |
| | | 18 | | /// <param name="key4">The fourth checked key.</param> |
| | | 19 | | /// <returns>System.String.</returns> |
| | | 20 | | public static string? GetFirstNotNullNorWhiteSpaceValue(this IReadOnlyDictionary<string, string> dictionary, str |
| | | 21 | | { |
| | 62 | 22 | | if (dictionary.TryGetValue(key1, out var val) && !string.IsNullOrWhiteSpace(val)) |
| | | 23 | | { |
| | 6 | 24 | | return val; |
| | | 25 | | } |
| | | 26 | | |
| | 56 | 27 | | if (!string.IsNullOrEmpty(key2) && dictionary.TryGetValue(key2, out val) && !string.IsNullOrWhiteSpace(val)) |
| | | 28 | | { |
| | 2 | 29 | | return val; |
| | | 30 | | } |
| | | 31 | | |
| | 54 | 32 | | if (!string.IsNullOrEmpty(key3) && dictionary.TryGetValue(key3, out val) && !string.IsNullOrWhiteSpace(val)) |
| | | 33 | | { |
| | 3 | 34 | | return val; |
| | | 35 | | } |
| | | 36 | | |
| | 51 | 37 | | if (!string.IsNullOrEmpty(key4) && dictionary.TryGetValue(key4, out val) && !string.IsNullOrWhiteSpace(val)) |
| | | 38 | | { |
| | 0 | 39 | | return val; |
| | | 40 | | } |
| | | 41 | | |
| | 51 | 42 | | return null; |
| | | 43 | | } |
| | | 44 | | } |
| | | 45 | | } |