From 486a07602bcf49f6ffee0114632b4910f26d63dd Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 12 Mar 2023 12:09:47 +0000 Subject: [PATCH] Fix CA1304 --- .editorconfig | 3 +++ OpenRA.Game/Exts.cs | 5 ----- .../20210321/UnhardcodeBaseBuilderBotModule.cs | 2 +- .../Rules/20210321/UnhardcodeSquadManager.cs | 4 ++-- .../Widgets/Logic/ReplayBrowserLogic.cs | 15 +++++++++------ 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.editorconfig b/.editorconfig index f53d1af2ae..d573f7b977 100644 --- a/.editorconfig +++ b/.editorconfig @@ -664,6 +664,9 @@ dotnet_diagnostic.CA1200.severity = warning ### Globalization Rules ### https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/globalization-warnings +# Specify 'CultureInfo'. +dotnet_diagnostic.CA1304.severity = warning + ### Portability and Interoperability Rules ### https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/interoperability-warnings diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 06a9f70a38..96016b5b21 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -22,11 +22,6 @@ namespace OpenRA { public static class Exts { - public static bool IsUppercase(this string str) - { - return string.Compare(str.ToUpperInvariant(), str, false) == 0; - } - public static T WithDefault(T def, Func f) { try { return f(); } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeBaseBuilderBotModule.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeBaseBuilderBotModule.cs index 9fcc4a100e..d07e5ec69a 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeBaseBuilderBotModule.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeBaseBuilderBotModule.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules if (isBuildable && isBuilding && canAttack) { - var name = actor.Key.ToLower(); + var name = actor.Key.ToLowerInvariant(); if (!defences.Contains(name)) defences.Add(name); } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeSquadManager.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeSquadManager.cs index ef97a77c01..83efc3360e 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeSquadManager.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20210321/UnhardcodeSquadManager.cs @@ -93,14 +93,14 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules if (isAircraft && isBuildable && canAttack && isKillable) { - var name = actor.Key.ToLower(); + var name = actor.Key.ToLowerInvariant(); if (!aircraft.Contains(name)) aircraft.Add(name); } if (isBuildable && isKillable && (isVip || (isBuilding && !isExcluded))) { - var name = actor.Key.ToLower(); + var name = actor.Key.ToLowerInvariant(); if (!vips.Contains(name)) vips.Add(name); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index 75babf34a8..22319cce55 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -390,7 +390,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var item = ScrollItemWidget.Setup( tpl, - () => string.Compare(filter.MapName, option, true) == 0, + () => string.Equals(filter.MapName, option, StringComparison.CurrentCultureIgnoreCase), () => { filter.MapName = option; ApplyFilter(); }); item.Get("LABEL").GetText = () => option ?? anyText; return item; @@ -418,7 +418,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var item = ScrollItemWidget.Setup( tpl, - () => string.Compare(filter.PlayerName, option, true) == 0, + () => string.Equals(filter.PlayerName, option, StringComparison.CurrentCultureIgnoreCase), () => { filter.PlayerName = option; ApplyFilter(); }); item.Get("LABEL").GetText = () => option ?? anyText; return item; @@ -450,7 +450,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var item = ScrollItemWidget.Setup( tpl, - () => string.Compare(filter.Faction, option, true) == 0, + () => string.Equals(filter.Faction, option, StringComparison.CurrentCultureIgnoreCase), () => { filter.Faction = option; ApplyFilter(); }); item.Get("LABEL").GetText = () => option ?? anyText; return item; @@ -658,13 +658,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic } // Map - if (!string.IsNullOrEmpty(filter.MapName) && string.Compare(filter.MapName, replay.GameInfo.MapTitle, true) != 0) + if (!string.IsNullOrEmpty(filter.MapName) && + !string.Equals(filter.MapName, replay.GameInfo.MapTitle, StringComparison.CurrentCultureIgnoreCase)) return false; // Player if (!string.IsNullOrEmpty(filter.PlayerName)) { - var player = replay.GameInfo.Players.FirstOrDefault(p => string.Compare(filter.PlayerName, p.Name, true) == 0); + var player = replay.GameInfo.Players.FirstOrDefault( + p => string.Equals(filter.PlayerName, p.Name, StringComparison.CurrentCultureIgnoreCase)); if (player == null) return false; @@ -673,7 +675,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic return false; // Faction - if (!string.IsNullOrEmpty(filter.Faction) && string.Compare(filter.Faction, player.FactionName, true) != 0) + if (!string.IsNullOrEmpty(filter.Faction) && + !string.Equals(filter.Faction, player.FactionName, StringComparison.CurrentCultureIgnoreCase)) return false; }