diff --git a/src/common/AllExperiments/Experiments.cs b/src/common/AllExperiments/Experiments.cs index 38ac694637..426e7af1d1 100644 --- a/src/common/AllExperiments/Experiments.cs +++ b/src/common/AllExperiments/Experiments.cs @@ -76,9 +76,10 @@ namespace AllExperiments if (jsonDictionary != null) { - if (!jsonDictionary.ContainsKey("dataversion")) + if (!jsonDictionary.TryGetValue("dataversion", out object? value)) { - jsonDictionary.Add("dataversion", dataVersion); + value = dataVersion; + jsonDictionary.Add("dataversion", value); } if (!jsonDictionary.ContainsKey("variantassignment")) @@ -87,7 +88,7 @@ namespace AllExperiments } else { - var jsonDataVersion = jsonDictionary["dataversion"].ToString(); + var jsonDataVersion = value.ToString(); if (jsonDataVersion != null && int.Parse(jsonDataVersion, CultureInfo.InvariantCulture) < dataVersion) { jsonDictionary["dataversion"] = dataVersion; @@ -116,9 +117,9 @@ namespace AllExperiments if (jsonDictionary != null) { - if (jsonDictionary.ContainsKey("variantassignment")) + if (jsonDictionary.TryGetValue("variantassignment", out object? value)) { - if (jsonDictionary["variantassignment"].ToString() == "alternate" && AssignmentUnit != string.Empty) + if (value.ToString() == "alternate" && AssignmentUnit != string.Empty) { IsExperiment = true; } diff --git a/src/common/ManagedCommon/ColorFormatHelper.cs b/src/common/ManagedCommon/ColorFormatHelper.cs index 8c40ea4978..08e62b921d 100644 --- a/src/common/ManagedCommon/ColorFormatHelper.cs +++ b/src/common/ManagedCommon/ColorFormatHelper.cs @@ -328,13 +328,13 @@ namespace ManagedCommon char paramFormat; string paramType = formatString.Substring(formatterPosition + 1, 2); int paramCount = 3; - if (DefaultFormatTypes.ContainsKey(paramType)) + if (DefaultFormatTypes.TryGetValue(paramType, out char value)) { // check the next char, which could be a formatter if (formatterPosition >= formatString.Length - 3) { // not enough characters, end of string, no formatter, use the default one - paramFormat = DefaultFormatTypes[paramType]; + paramFormat = value; paramCount = 2; } else @@ -344,7 +344,7 @@ namespace ManagedCommon // check if it a valid formatter if (!FormatTypeToStringFormatters.ContainsKey(paramFormat)) { - paramFormat = DefaultFormatTypes[paramType]; + paramFormat = value; paramCount = 2; } } diff --git a/src/modules/MouseWithoutBorders/App/Class/Common.Encryption.cs b/src/modules/MouseWithoutBorders/App/Class/Common.Encryption.cs index 7a0562b845..33f5289419 100644 --- a/src/modules/MouseWithoutBorders/App/Class/Common.Encryption.cs +++ b/src/modules/MouseWithoutBorders/App/Class/Common.Encryption.cs @@ -115,7 +115,7 @@ namespace MouseWithoutBorders byte[] rv; string myKey = Common.MyKey; - if (!LegalKeyDictionary.ContainsKey(myKey)) + if (!LegalKeyDictionary.TryGetValue(myKey, out byte[] value)) { Rfc2898DeriveBytes key = new( myKey, @@ -127,7 +127,7 @@ namespace MouseWithoutBorders } else { - rv = LegalKeyDictionary[myKey]; + rv = value; } return rv; diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutHotkeysModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutHotkeysModel.cs index 54311b4b03..f8b783768a 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutHotkeysModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutHotkeysModel.cs @@ -43,12 +43,12 @@ namespace FancyZonesEditor.Models public bool SelectKey(string key, string uuid) { - if (!SelectedKeys.ContainsKey(key)) + if (!SelectedKeys.TryGetValue(key, out string value)) { return false; } - if (SelectedKeys[key] == uuid) + if (value == uuid) { return true; } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs index e575ad99cf..5ad6f59955 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Main.cs @@ -201,12 +201,13 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal { var aumid = terminal.AppUserModelId; - if (!_logoCache.ContainsKey(aumid)) + if (!_logoCache.TryGetValue(aumid, out BitmapImage value)) { - _logoCache.Add(aumid, terminal.GetLogo()); + value = terminal.GetLogo(); + _logoCache.Add(aumid, value); } - return _logoCache[aumid]; + return value; } } } diff --git a/src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs b/src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs index cbb98683e8..5b8dde37a6 100644 --- a/src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs +++ b/src/modules/launcher/PowerLauncher/Helper/EnvironmentHelper.cs @@ -50,9 +50,9 @@ namespace PowerLauncher.Helper string pVarKey = (string)pVar.Key; string pVarValue = (string)pVar.Value; - if (machineAndUserVars.ContainsKey(pVarKey)) + if (machineAndUserVars.TryGetValue(pVarKey, out string value)) { - if (machineAndUserVars[pVarKey] != pVarValue) + if (value != pVarValue) { // Variable value for this process differs form merged machine/user value. _protectedProcessVariables.Add(pVarKey); diff --git a/src/modules/launcher/PowerLauncher/SettingsReader.cs b/src/modules/launcher/PowerLauncher/SettingsReader.cs index 98abae4318..70f3253f5d 100644 --- a/src/modules/launcher/PowerLauncher/SettingsReader.cs +++ b/src/modules/launcher/PowerLauncher/SettingsReader.cs @@ -248,14 +248,14 @@ namespace PowerLauncher var defaultPlugins = GetDefaultPluginsSettings().ToDictionary(x => x.Id); foreach (PowerLauncherPluginSettings plugin in settings.Plugins) { - if (defaultPlugins.ContainsKey(plugin.Id)) + if (defaultPlugins.TryGetValue(plugin.Id, out PowerLauncherPluginSettings value)) { - var additionalOptions = CombineAdditionalOptions(defaultPlugins[plugin.Id].AdditionalOptions, plugin.AdditionalOptions); - plugin.Name = defaultPlugins[plugin.Id].Name; - plugin.Description = defaultPlugins[plugin.Id].Description; - plugin.Author = defaultPlugins[plugin.Id].Author; - plugin.IconPathDark = defaultPlugins[plugin.Id].IconPathDark; - plugin.IconPathLight = defaultPlugins[plugin.Id].IconPathLight; + var additionalOptions = CombineAdditionalOptions(value.AdditionalOptions, plugin.AdditionalOptions); + plugin.Name = value.Name; + plugin.Description = value.Description; + plugin.Author = value.Author; + plugin.IconPathDark = value.IconPathDark; + plugin.IconPathLight = value.IconPathLight; defaultPlugins[plugin.Id] = plugin; defaultPlugins[plugin.Id].AdditionalOptions = additionalOptions; } diff --git a/src/modules/launcher/Wox.Infrastructure/Alphabet.cs b/src/modules/launcher/Wox.Infrastructure/Alphabet.cs index 0d067c7953..fb81591047 100644 --- a/src/modules/launcher/Wox.Infrastructure/Alphabet.cs +++ b/src/modules/launcher/Wox.Infrastructure/Alphabet.cs @@ -134,7 +134,7 @@ public class Alphabet : IAlphabet return _empty2DStringArray; } - if (!_pinyinCache.ContainsKey(characters)) + if (!_pinyinCache.TryGetValue(characters, out string[][] value)) { var allPinyins = new List(); foreach (var c in characters) @@ -158,7 +158,7 @@ public class Alphabet : IAlphabet } else { - return _pinyinCache[characters]; + return value; } }