Add more `GetValueOrDefault` overloads
This commit is contained in:
parent
72b2e78957
commit
34d71e90bc
|
@ -153,6 +153,10 @@ namespace BizHawk.Common.CollectionExtensions
|
|||
/// If the key is not present, returns default(TValue).
|
||||
/// backported from .NET Core 2.0
|
||||
/// </summary>
|
||||
public static TValue? GetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue> dictionary, TKey key)
|
||||
=> dictionary.TryGetValue(key, out var found) ? found : default;
|
||||
|
||||
/// <inheritdoc cref="GetValueOrDefault{K,V}(IDictionary{K,V},K)"/>
|
||||
public static TValue? GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
|
||||
=> dictionary.TryGetValue(key, out var found) ? found : default;
|
||||
|
||||
|
@ -161,6 +165,10 @@ namespace BizHawk.Common.CollectionExtensions
|
|||
/// If the key is not present, returns <paramref name="defaultValue"/>.
|
||||
/// backported from .NET Core 2.0
|
||||
/// </summary>
|
||||
public static TValue? GetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
|
||||
=> dictionary.TryGetValue(key, out var found) ? found : defaultValue;
|
||||
|
||||
/// <inheritdoc cref="GetValueOrDefault{K,V}(IDictionary{K,V},K,V)"/>
|
||||
public static TValue? GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
|
||||
=> dictionary.TryGetValue(key, out var found) ? found : defaultValue;
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue