diff --git a/.global.editorconfig.ini b/.global.editorconfig.ini index 0882a171ac..7737c59e4e 100644 --- a/.global.editorconfig.ini +++ b/.global.editorconfig.ini @@ -93,6 +93,8 @@ dotnet_diagnostic.CA1829.severity = error dotnet_diagnostic.CA1836.severity = error # Avoid StringBuilder parameters for P/Invokes dotnet_diagnostic.CA1838.severity = suggestion +# Prefer the `IDictionary.TryGetValue(TKey, out TValue)` method +dotnet_diagnostic.CA1854.severity = warning # Avoid using 'Enumerable.Any()' extension method dotnet_diagnostic.CA1860.severity = error # Use the 'StringComparison' method overloads to perform case-insensitive string comparisons diff --git a/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs b/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs index 8bc9138000..0c674b1fb2 100644 --- a/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs @@ -144,14 +144,12 @@ namespace BizHawk.Client.EmuHawk : "Console"; // anything that wants not console can set it in the categorylabels } - if (!buckets.ContainsKey(categoryLabel)) + buckets.GetValueOrPut(categoryLabel, categoryLabel1 => { - var l = new List(); - buckets.Add(categoryLabel, l); - orderedBuckets.Add(new KeyValuePair>(categoryLabel, l)); - } - - buckets[categoryLabel].Add(button); + List l = new(); + orderedBuckets.Add(new(categoryLabel1, l)); + return l; + }).Add(button); } if (orderedBuckets.Count == 1) diff --git a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.ButtonNameOverrides.cs b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.ButtonNameOverrides.cs index a6a8f210b0..01f7e87289 100644 --- a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.ButtonNameOverrides.cs +++ b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.ButtonNameOverrides.cs @@ -36,9 +36,9 @@ namespace BizHawk.Emulation.Cores.Waterbox private string OverrideButtonName(string original) { // VB hack - if (ButtonNameOverrides.ContainsKey(original)) + if (ButtonNameOverrides.TryGetValue(original, out string vbOverrideName)) { - original = ButtonNameOverrides[original]; + original = vbOverrideName; } original = Regex.Replace(original, @"\s*(↑|↓|←|→)\s*", ""); @@ -48,9 +48,9 @@ namespace BizHawk.Emulation.Cores.Waterbox original = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(original.ToLowerInvariant()); } - if (ButtonNameOverrides.ContainsKey(original)) + if (ButtonNameOverrides.TryGetValue(original, out string overrideName)) { - original = ButtonNameOverrides[original]; + original = overrideName; } // TODO: Add dictionaries or whatever here as needed