From 34d71e90bcd7ace6736363553083b925b5bf888f Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 23 Aug 2024 02:15:24 +1000 Subject: [PATCH] Add more `GetValueOrDefault` overloads --- src/BizHawk.Common/Extensions/CollectionExtensions.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/BizHawk.Common/Extensions/CollectionExtensions.cs b/src/BizHawk.Common/Extensions/CollectionExtensions.cs index 5af174e14d..8159f09ab7 100644 --- a/src/BizHawk.Common/Extensions/CollectionExtensions.cs +++ b/src/BizHawk.Common/Extensions/CollectionExtensions.cs @@ -153,6 +153,10 @@ namespace BizHawk.Common.CollectionExtensions /// If the key is not present, returns default(TValue). /// backported from .NET Core 2.0 /// + public static TValue? GetValueOrDefault(IDictionary dictionary, TKey key) + => dictionary.TryGetValue(key, out var found) ? found : default; + + /// public static TValue? GetValueOrDefault(this IReadOnlyDictionary 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 . /// backported from .NET Core 2.0 /// + public static TValue? GetValueOrDefault(IDictionary dictionary, TKey key, TValue defaultValue) + => dictionary.TryGetValue(key, out var found) ? found : defaultValue; + + /// public static TValue? GetValueOrDefault(this IReadOnlyDictionary dictionary, TKey key, TValue defaultValue) => dictionary.TryGetValue(key, out var found) ? found : defaultValue; #endif