mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-11-13 20:33:45 +01:00
44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
namespace System.Collections.Generic;
|
|
|
|
internal static class DictionaryExtensions
|
|
{
|
|
#if NETSTANDARD2_0
|
|
public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue>? dictionary, TKey key, TValue value)
|
|
{
|
|
if (dictionary is null || dictionary.ContainsKey(key))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
dictionary[key] = value;
|
|
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
public static bool TryGetFirstValue<TKey, TValue>(this IDictionary<TKey, TValue>? dictionary, out TValue? value)
|
|
{
|
|
if (dictionary != null && dictionary.Count > 0)
|
|
{
|
|
value = dictionary.First().Value;
|
|
return true;
|
|
}
|
|
|
|
value = default;
|
|
return false;
|
|
}
|
|
|
|
public static bool TryGetFirstOrDefault<TKey, TValue>(this IDictionary<TKey, TValue>? dictionary, out KeyValuePair<TKey, TValue> value)
|
|
{
|
|
if (dictionary != null && dictionary.Count > 0)
|
|
{
|
|
value = dictionary.First();
|
|
return true;
|
|
}
|
|
|
|
value = default;
|
|
return false;
|
|
}
|
|
} |