diff --git a/.editorconfig b/.editorconfig index 435455fe31..044b1a1115 100644 --- a/.editorconfig +++ b/.editorconfig @@ -892,9 +892,15 @@ dotnet_diagnostic.CA2247.severity = warning # Provide correct enum argument to Enum.HasFlag. dotnet_diagnostic.CA2248.severity = warning +# Consider using String.Contains instead of String.IndexOf. +dotnet_diagnostic.CA2249.severity = warning + # Use ThrowIfCancellationRequested. dotnet_diagnostic.CA2250.severity = warning +# Use String.Equals over String.Compare. +dotnet_diagnostic.CA2251.severity = warning + # Ensure ThreadStatic is only used with static fields. dotnet_diagnostic.CA2259.severity = warning diff --git a/OpenRA.Game/GameRules/ActorInfo.cs b/OpenRA.Game/GameRules/ActorInfo.cs index a064db6ffa..035549ad5d 100644 --- a/OpenRA.Game/GameRules/ActorInfo.cs +++ b/OpenRA.Game/GameRules/ActorInfo.cs @@ -22,7 +22,7 @@ namespace OpenRA /// public class ActorInfo { - public const string AbstractActorPrefix = "^"; + public const char AbstractActorPrefix = '^'; public const char TraitInstanceSeparator = '@'; /// diff --git a/OpenRA.Game/GameRules/Ruleset.cs b/OpenRA.Game/GameRules/Ruleset.cs index 312c6805aa..0c6f938900 100644 --- a/OpenRA.Game/GameRules/Ruleset.cs +++ b/OpenRA.Game/GameRules/Ruleset.cs @@ -124,7 +124,7 @@ namespace OpenRA { var actors = MergeOrDefault("Manifest,Rules", fs, m.Rules, null, null, k => new ActorInfo(modData.ObjectCreator, k.Key.ToLowerInvariant(), k.Value), - filterNode: n => n.Key.StartsWith(ActorInfo.AbstractActorPrefix, StringComparison.Ordinal)); + filterNode: n => n.Key.StartsWith(ActorInfo.AbstractActorPrefix)); var weapons = MergeOrDefault("Manifest,Weapons", fs, m.Weapons, null, null, k => new WeaponInfo(k.Value)); @@ -182,7 +182,7 @@ namespace OpenRA { var actors = MergeOrDefault("Rules", fileSystem, m.Rules, mapRules, dr.Actors, k => new ActorInfo(modData.ObjectCreator, k.Key.ToLowerInvariant(), k.Value), - filterNode: n => n.Key.StartsWith(ActorInfo.AbstractActorPrefix, StringComparison.Ordinal)); + filterNode: n => n.Key.StartsWith(ActorInfo.AbstractActorPrefix)); var weapons = MergeOrDefault("Weapons", fileSystem, m.Weapons, mapWeapons, dr.Weapons, k => new WeaponInfo(k.Value)); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs index 14d40b9716..c22bc2c9e2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs @@ -491,7 +491,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public void Do() { - actor = editorActorLayer[actorId.ToLowerInvariant()]; + actor = editorActorLayer[actorId]; foreach (var editorActionHandle in handles) editorActionHandle.Do(actor); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs index f89ace6fdc..5e945aeac4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs @@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (!string.IsNullOrEmpty(searchFilter)) FilteredCategories.AddRange( allActors.Where(t => t.SearchTerms.Any( - s => s.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0)) + s => s.Contains(searchFilter, StringComparison.CurrentCultureIgnoreCase))) .SelectMany(t => t.Categories) .Distinct() .OrderBy(x => x)); @@ -181,7 +181,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (!SelectedCategories.Overlaps(a.Categories)) continue; - if (!string.IsNullOrEmpty(searchFilter) && !a.SearchTerms.Any(s => s.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0)) + if (!string.IsNullOrEmpty(searchFilter) && + !a.SearchTerms.Any(s => s.Contains(searchFilter, StringComparison.CurrentCultureIgnoreCase))) continue; var actor = a.Actor; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/TileSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/TileSelectorLogic.cs index 1601b952b3..440510b54f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/TileSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/TileSelectorLogic.cs @@ -102,7 +102,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (!SelectedCategories.Overlaps(t.Categories)) continue; - if (!string.IsNullOrEmpty(searchFilter) && !t.SearchTerms.Any(s => s.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0)) + if (!string.IsNullOrEmpty(searchFilter) && + !t.SearchTerms.Any(s => s.Contains(searchFilter, StringComparison.CurrentCultureIgnoreCase))) continue; var tileId = t.Template.Id; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index ed2d2b77b9..73c14c5555 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -325,8 +325,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic var validMaps = tabMaps[tab] .Where(m => category == null || m.Categories.Contains(category)) .Where(m => mapFilter == null || - (m.Title != null && m.Title.IndexOf(mapFilter, StringComparison.OrdinalIgnoreCase) >= 0) || - (m.Author != null && m.Author.IndexOf(mapFilter, StringComparison.OrdinalIgnoreCase) >= 0) || + (m.Title != null && m.Title.Contains(mapFilter, StringComparison.CurrentCultureIgnoreCase)) || + (m.Author != null && m.Author.Contains(mapFilter, StringComparison.CurrentCultureIgnoreCase)) || m.PlayerCount == playerCountFilter); IOrderedEnumerable maps; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs index b364cbf041..5848cdd99d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs @@ -322,7 +322,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic bool IsHotkeyVisibleInFilter(HotkeyDefinition hd) { var filter = filterInput.Text; - var isFilteredByName = string.IsNullOrWhiteSpace(filter) || hd.Description.Contains(filter, StringComparison.OrdinalIgnoreCase); + var isFilteredByName = string.IsNullOrWhiteSpace(filter) || + hd.Description.Contains(filter, StringComparison.CurrentCultureIgnoreCase); var isFilteredByContext = currentContext == "Any" || hd.Contexts.Contains(currentContext); return isFilteredByName && isFilteredByContext;