24 lines
615 B
C#
24 lines
615 B
C#
|
namespace Piwigo.Client;
|
||
|
|
||
|
internal static class DictionaryExtensions
|
||
|
{
|
||
|
public static IDictionary<string, string> AddIfValueNotNull(this IDictionary<string, string> dictionary, string key, string? value)
|
||
|
{
|
||
|
if (dictionary == null)
|
||
|
{
|
||
|
throw new ArgumentNullException(nameof(dictionary));
|
||
|
}
|
||
|
|
||
|
if (string.IsNullOrWhiteSpace(key))
|
||
|
{
|
||
|
throw new ArgumentException("Value cannot be null or whitespace.", nameof(key));
|
||
|
}
|
||
|
|
||
|
if (value is not null)
|
||
|
{
|
||
|
dictionary.Add(key, value);
|
||
|
}
|
||
|
|
||
|
return dictionary;
|
||
|
}
|
||
|
}
|