diff --git a/.editorconfig b/.editorconfig index 3b441db9e1..4a25f15793 100644 --- a/.editorconfig +++ b/.editorconfig @@ -858,6 +858,9 @@ dotnet_diagnostic.CA1858.severity = warning # Avoid using 'Enumerable.Any()' extension method. dotnet_diagnostic.CA1860.severity = warning +# Prefer the 'IDictionary.TryAdd(TKey, TValue)' method. +dotnet_diagnostic.CA1864.severity = suggestion # TODO: Change to warning once using .NET 8 or later. + # Cache and reuse 'JsonSerializerOptions' instances. dotnet_diagnostic.CA1869.severity = suggestion # TODO: Change to warning once using .NET 8 or later. diff --git a/OpenRA.Mods.Common/Installer/SourceActions/ExtractBlastSourceAction.cs b/OpenRA.Mods.Common/Installer/SourceActions/ExtractBlastSourceAction.cs index 6bdc76ddf6..3d9ca394ed 100644 --- a/OpenRA.Mods.Common/Installer/SourceActions/ExtractBlastSourceAction.cs +++ b/OpenRA.Mods.Common/Installer/SourceActions/ExtractBlastSourceAction.cs @@ -43,8 +43,7 @@ namespace OpenRA.Mods.Common.Installer source.Position += 13; // This does not apply on game relevant data. - if (!entries.ContainsKey(key)) - entries.Add(key, entry); + entries.TryAdd(key, entry); } foreach (var node in actionYaml.Nodes) diff --git a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs index f247b853b5..a6c3398573 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs @@ -72,8 +72,7 @@ namespace OpenRA.Mods.Common.Traits continue; // Add power to dictionary if not in delay dictionary yet - if (!waitingPowers.ContainsKey(sp)) - waitingPowers.Add(sp, 0); + waitingPowers.TryAdd(sp, 0); if (waitingPowers[sp] > 0) waitingPowers[sp]--;