Fix CA1310, CA1311

This commit is contained in:
RoosterDragon
2023-03-12 15:44:49 +00:00
committed by Matthias Mailänder
parent d83e579dfe
commit 285443f10f
43 changed files with 80 additions and 67 deletions

View File

@@ -670,6 +670,12 @@ dotnet_diagnostic.CA1304.severity = warning
# Specify 'IFormatProvider'.
dotnet_diagnostic.CA1305.severity = warning
# Specify 'StringComparison' for correctness.
dotnet_diagnostic.CA1310.severity = warning
# Specify a culture or use an invariant version.
dotnet_diagnostic.CA1311.severity = warning
### Portability and Interoperability Rules
### https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/interoperability-warnings

View File

@@ -83,14 +83,14 @@ namespace OpenRA.FileSystem
public void Mount(string name, string explicitName = null)
{
var optional = name.StartsWith("~", StringComparison.Ordinal);
var optional = name.StartsWith('~');
if (optional)
name = name[1..];
try
{
IReadOnlyPackage package;
if (name.StartsWith("$", StringComparison.Ordinal))
if (name.StartsWith('$'))
{
name = name[1..];
@@ -295,7 +295,7 @@ namespace OpenRA.FileSystem
public static string ResolveAssemblyPath(string path, Manifest manifest, InstalledMods installedMods)
{
var explicitSplit = path.IndexOf('|');
if (explicitSplit > 0 && !path.StartsWith("^"))
if (explicitSplit > 0 && !path.StartsWith('^'))
{
var parent = path[..explicitSplit];
var filename = path[(explicitSplit + 1)..];
@@ -304,7 +304,7 @@ namespace OpenRA.FileSystem
if (parentPath == null)
return null;
if (parentPath.StartsWith("$", StringComparison.Ordinal))
if (parentPath.StartsWith('$'))
{
if (!installedMods.TryGetValue(parentPath[1..], out var mod))
return null;

View File

@@ -80,7 +80,7 @@ namespace OpenRA.FileSystem
// in FileSystem.OpenPackage. Their internal name therefore contains the
// full parent path too. We need to be careful to not add a second path
// prefix to these hacked packages.
var filePath = filename.StartsWith(Name) ? filename : Path.Combine(Name, filename);
var filePath = filename.StartsWith(Name, StringComparison.Ordinal) ? filename : Path.Combine(Name, filename);
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
using (var s = File.Create(filePath))
@@ -94,7 +94,7 @@ namespace OpenRA.FileSystem
// in FileSystem.OpenPackage. Their internal name therefore contains the
// full parent path too. We need to be careful to not add a second path
// prefix to these hacked packages.
var filePath = filename.StartsWith(Name) ? filename : Path.Combine(Name, filename);
var filePath = filename.StartsWith(Name, StringComparison.Ordinal) ? filename : Path.Combine(Name, filename);
if (Directory.Exists(filePath))
Directory.Delete(filePath, true);
else if (File.Exists(filePath))

View File

@@ -159,7 +159,7 @@ namespace OpenRA.GameRules
static object LoadWarheads(MiniYaml yaml)
{
var retList = new List<IWarhead>();
foreach (var node in yaml.Nodes.Where(n => n.Key.StartsWith("Warhead")))
foreach (var node in yaml.Nodes.Where(n => n.Key.StartsWith("Warhead", StringComparison.Ordinal)))
{
var ret = Game.CreateObject<IWarhead>(node.Value.Value + "Warhead");
if (ret == null)

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Graphics
.Select(s => MiniYaml.FromStream(fileSystem.Open(s), s)));
foreach (var c in chrome)
if (!c.Key.StartsWith("^", StringComparison.Ordinal))
if (!c.Key.StartsWith('^'))
LoadCollection(c.Key, c.Value);
}

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Graphics
foreach (var node in nodes)
{
// Nodes starting with ^ are inheritable but never loaded directly
if (node.Key.StartsWith(ActorInfo.AbstractActorPrefix, StringComparison.Ordinal))
if (node.Key.StartsWith(ActorInfo.AbstractActorPrefix))
continue;
images[node.Key] = modData.SpriteSequenceLoader.ParseSequences(modData, tileSet, SpriteCache, node);

View File

@@ -275,7 +275,10 @@ namespace OpenRA
try
{
foreach (var filename in contents)
if (filename.EndsWith(".yaml") || filename.EndsWith(".bin") || filename.EndsWith(".lua") || (format >= 12 && filename == "map.png"))
if (filename.EndsWith(".yaml", StringComparison.Ordinal) ||
filename.EndsWith(".bin", StringComparison.Ordinal) ||
filename.EndsWith(".lua", StringComparison.Ordinal) ||
(format >= 12 && filename == "map.png"))
streams.Add(package.GetStream(filename));
// Take the SHA1

View File

@@ -97,7 +97,7 @@ namespace OpenRA
? MapClassification.Unknown : Enum<MapClassification>.Parse(kv.Value);
IReadOnlyPackage package;
var optional = name.StartsWith("~", StringComparison.Ordinal);
var optional = name.StartsWith('~');
if (optional)
name = name[1..];
@@ -106,7 +106,7 @@ namespace OpenRA
// HACK: If the path is inside the support directory then we may need to create it
// Assume that the path is a directory if there is not an existing file with the same name
var resolved = Platform.ResolvePath(name);
if (resolved.StartsWith(Platform.SupportDir) && !File.Exists(resolved))
if (resolved.StartsWith(Platform.SupportDir, StringComparison.Ordinal) && !File.Exists(resolved))
Directory.CreateDirectory(resolved);
package = modData.ModFiles.OpenPackage(name);
@@ -190,13 +190,13 @@ namespace OpenRA
continue;
var name = kv.Key;
var optional = name.StartsWith("~", StringComparison.Ordinal);
var optional = name.StartsWith('~');
if (optional)
name = name[1..];
// Don't try to open the map directory in the support directory if it doesn't exist
var resolved = Platform.ResolvePath(name);
if (resolved.StartsWith(Platform.SupportDir) && (!Directory.Exists(resolved) || !File.Exists(resolved)))
if (resolved.StartsWith(Platform.SupportDir, StringComparison.Ordinal) && (!Directory.Exists(resolved) || !File.Exists(resolved)))
continue;
using (var package = (IReadWritePackage)modData.ModFiles.OpenPackage(name))

View File

@@ -438,7 +438,7 @@ namespace OpenRA
foreach (var r in ResolveInherits(parent, tree, inherited))
MergeIntoResolved(r, resolved, resolvedKeys, tree, inherited);
}
else if (n.Key.StartsWith("-", StringComparison.Ordinal))
else if (n.Key.StartsWith('-'))
{
var removed = n.Key[1..];
if (resolved.RemoveAll(r => r.Key == removed) == 0)

View File

@@ -109,14 +109,14 @@ namespace OpenRA
var p = Process.Start(psi);
string line;
while ((line = p.StandardOutput.ReadLine()) != null)
if (line.StartsWith("Operating System: "))
if (line.StartsWith("Operating System: ", StringComparison.Ordinal))
return line[18..] + suffix;
}
catch { }
if (File.Exists("/etc/os-release"))
foreach (var line in File.ReadLines("/etc/os-release"))
if (line.StartsWith("PRETTY_NAME="))
if (line.StartsWith("PRETTY_NAME=", StringComparison.Ordinal))
return line[13..^1] + suffix;
}
else if (CurrentPlatform == PlatformType.OSX)
@@ -134,7 +134,7 @@ namespace OpenRA
while ((line = p.StandardOutput.ReadLine()) != null)
{
line = line.Trim();
if (line.StartsWith("System Version: "))
if (line.StartsWith("System Version: ", StringComparison.Ordinal))
return line[16..];
}
}

View File

@@ -150,7 +150,7 @@ namespace OpenRA.Scripting
// Remove the namespace and the trailing "Info"
return types.SelectMany(i => i.GetGenericArguments())
.Select(g => g.Name.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault())
.Select(s => s.EndsWith("Info") ? s.Remove(s.Length - 4, 4) : s)
.Select(s => s.EndsWith("Info", StringComparison.Ordinal) ? s.Remove(s.Length - 4, 4) : s)
.ToArray();
}
}

View File

@@ -86,9 +86,9 @@ namespace OpenRA
{
// Always load english strings to provide a fallback for missing translations.
// It is important to load the english files first so the chosen language's files can override them.
var paths = translations.Where(t => t.EndsWith("en.ftl")).ToHashSet();
var paths = translations.Where(t => t.EndsWith("en.ftl", StringComparison.Ordinal)).ToHashSet();
foreach (var t in translations)
if (t.EndsWith($"{language}.ftl"))
if (t.EndsWith($"{language}.ftl", StringComparison.Ordinal))
paths.Add(t);
foreach (var path in paths)

View File

@@ -116,7 +116,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
{
var vfh = VocFileHeader.Read(stream);
if (!vfh.Description.StartsWith("Creative Voice File"))
if (!vfh.Description.StartsWith("Creative Voice File", StringComparison.Ordinal))
throw new InvalidDataException("Voc header description not recognized");
if (vfh.DatablockOffset != 26)
throw new InvalidDataException("Voc header offset is wrong");

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.IO;
@@ -111,7 +112,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
public VxlReader(Stream s)
{
if (!s.ReadASCII(16).StartsWith("Voxel Animation"))
if (!s.ReadASCII(16).StartsWith("Voxel Animation", StringComparison.Ordinal))
throw new InvalidDataException("Invalid vxl header");
s.ReadUInt32();

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc.Installer
public void RunActionOnSource(MiniYaml actionYaml, string path, ModData modData, List<string> extracted, Action<string> updateMessage)
{
// Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected source path
var sourcePath = actionYaml.Value.StartsWith("^") ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
var sourcePath = actionYaml.Value.StartsWith('^') ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
using (var source = File.OpenRead(sourcePath))
{

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var player = basic.GetValue("Player", string.Empty);
if (!string.IsNullOrEmpty(player))
singlePlayer = !player.StartsWith("Multi");
singlePlayer = !player.StartsWith("Multi", StringComparison.Ordinal);
var mapSection = file.GetSection("Map");
@@ -332,9 +332,9 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var key = $"{loc % MapSize},{loc / MapSize}";
var value = $"{type},{parts[2]}";
var node = new MiniYamlNode(key, value);
if (type.StartsWith("sc"))
if (type.StartsWith("sc", StringComparison.Ordinal))
scorches.Add(node);
else if (type.StartsWith("cr"))
else if (type.StartsWith("cr", StringComparison.Ordinal))
craters.Add(node);
}

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Commands
public bool OnChat(string playername, string message)
{
if (message.StartsWith("/"))
if (message.StartsWith('/'))
{
var name = message[1..].Split(' ')[0].ToLowerInvariant();
var command = Commands.FirstOrDefault(x => x.Key == name);

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Installer
public void RunActionOnSource(MiniYaml actionYaml, string path, ModData modData, List<string> extracted, Action<string> updateMessage)
{
// Yaml path must be specified relative to a named directory (e.g. ^SupportDir)
if (!actionYaml.Value.StartsWith("^"))
if (!actionYaml.Value.StartsWith('^'))
return;
var sourcePath = Platform.ResolvePath(actionYaml.Value);

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Installer
public void RunActionOnSource(MiniYaml actionYaml, string path, ModData modData, List<string> extracted, Action<string> updateMessage)
{
// Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected source path
var sourcePath = actionYaml.Value.StartsWith("^") ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
var sourcePath = actionYaml.Value.StartsWith('^') ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
using (var source = File.OpenRead(sourcePath))
{

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Installer
public void RunActionOnSource(MiniYaml actionYaml, string path, ModData modData, List<string> extracted, Action<string> updateMessage)
{
// Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected source path
var sourcePath = actionYaml.Value.StartsWith("^") ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
var sourcePath = actionYaml.Value.StartsWith('^') ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
var volumeNode = actionYaml.Nodes.FirstOrDefault(n => n.Key == "Volumes");
if (volumeNode == null)

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Installer
public void RunActionOnSource(MiniYaml actionYaml, string path, ModData modData, List<string> extracted, Action<string> updateMessage)
{
// Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected source path
var sourcePath = actionYaml.Value.StartsWith("^") ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
var sourcePath = actionYaml.Value.StartsWith('^') ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
using (var source = File.OpenRead(sourcePath))
{

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Installer
public void RunActionOnSource(MiniYaml actionYaml, string path, ModData modData, List<string> extracted, Action<string> updateMessage)
{
// Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected source path
var sourcePath = actionYaml.Value.StartsWith("^") ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
var sourcePath = actionYaml.Value.StartsWith('^') ? Platform.ResolvePath(actionYaml.Value) : FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));
using (var source = File.OpenRead(sourcePath))
{

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Installer
public void RunActionOnSource(MiniYaml actionYaml, string path, ModData modData, List<string> extracted,
Action<string> updateMessage)
{
var zipPath = actionYaml.Value.StartsWith("^")
var zipPath = actionYaml.Value.StartsWith('^')
? Platform.ResolvePath(actionYaml.Value)
: FS.ResolveCaseInsensitivePath(Path.Combine(path, actionYaml.Value));

View File

@@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Lint
if (sequenceReference.Prefix)
{
// TODO: Remove prefixed sequence references and instead use explicit lists of lintable references.
if (!sequences.Sequences(i).Any(s => s.StartsWith(sequence)))
if (!sequences.Sequences(i).Any(s => s.StartsWith(sequence, StringComparison.Ordinal)))
emitWarning($"Actor type `{actorInfo.Value.Name}` trait `{traitName}` field `{field.Name}` defines a prefix `{sequence}` that does not match any sequences on image `{i}`.");
}
else if (!sequences.HasSequence(i, sequence))
@@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Lint
if (sequenceReference.Prefix)
{
// TODO: Remove prefixed sequence references and instead use explicit lists of lintable references.
if (!sequences.Sequences(image).Any(s => s.StartsWith(sequence)))
if (!sequences.Sequences(image).Any(s => s.StartsWith(sequence, StringComparison.Ordinal)))
emitWarning($"Weapon type `{weaponInfo.Key}` projectile field `{field.Name}` defines a prefix `{sequence}` that does not match any sequences on image `{image}`.");
}
else if (!sequences.HasSequence(image, sequence))

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Lint
static string NormalizeName(string key)
{
var name = key.Split('@')[0];
if (name.StartsWith("-", StringComparison.Ordinal))
if (name.StartsWith('-'))
return name[1..];
return name;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Lint
foreach (var t in actor.Value.Nodes)
{
// Removals can never define children or values.
if (t.Key.StartsWith("-", StringComparison.Ordinal))
if (t.Key.StartsWith('-'))
{
if (t.Value.Nodes.Length > 0)
emitError($"{t.Location} `{t.Key}` defines child nodes, which are not valid for removals.");

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Lint
static string NormalizeName(string key)
{
var name = key.Split('@')[0];
if (name.StartsWith("-", StringComparison.Ordinal))
if (name.StartsWith('-'))
return name[1..];
return name;
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Lint
foreach (var field in weapon.Value.Nodes)
{
// Removals can never define children or values
if (field.Key.StartsWith("-", StringComparison.Ordinal))
if (field.Key.StartsWith('-'))
{
if (field.Value.Nodes.Length > 0)
emitError($"{field.Location} `{field.Key}` defines child nodes, which is not valid for removals.");

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Lint
var bi = actorInfo.Value.TraitInfoOrDefault<BuildableInfo>();
if (bi != null)
foreach (var prereq in bi.Prerequisites)
if (!prereq.StartsWith("~disabled") && !providedPrereqs.Contains(prereq.Replace("!", "").Replace("~", "")))
if (!prereq.StartsWith("~disabled", StringComparison.Ordinal) && !providedPrereqs.Contains(prereq.Replace("!", "").Replace("~", "")))
emitError($"Buildable actor `{actorInfo.Key}` has prereq `{prereq}` not provided by anything.");
}
catch (InvalidOperationException e)

View File

@@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Server
lock (server.LobbyInfo)
{
// Kick command is always valid for the host
if (command.StartsWith("kick "))
if (command.StartsWith("kick ", StringComparison.Ordinal))
return true;
if (server.State == ServerState.GameStarted)
@@ -215,7 +215,7 @@ namespace OpenRA.Mods.Common.Server
server.SendLocalizedMessageTo(conn, StateUnchangedGameStarted, Translation.Arguments("command", command));
return false;
}
else if (client.State == Session.ClientState.Ready && !(command.StartsWith("state") || command == "startgame"))
else if (client.State == Session.ClientState.Ready && !(command.StartsWith("state", StringComparison.Ordinal) || command == "startgame"))
{
server.SendLocalizedMessageTo(conn, StateUnchangedReady);
return false;

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
List<float2> frameOffsets;
// Prefer manual defined regions over auto sliced regions.
if (png.EmbeddedData.Any(meta => meta.Key.StartsWith("Frame[")))
if (png.EmbeddedData.Any(meta => meta.Key.StartsWith("Frame[", StringComparison.Ordinal)))
RegionsFromFrames(png, out frameRegions, out frameOffsets);
else
RegionsFromSlices(png, out frameRegions, out frameOffsets);

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Traits;
@@ -110,7 +111,7 @@ namespace OpenRA.Mods.Common.Traits
{
// PERF: Avoid LINQ.
foreach (var pref in prefixes)
if (name.StartsWith(pref))
if (name.StartsWith(pref, StringComparison.Ordinal))
return true;
return false;

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
@@ -116,7 +117,7 @@ namespace OpenRA.Mods.Common.Traits
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString.StartsWith("Dev"))
if (order.OrderString.StartsWith("Dev", StringComparison.Ordinal))
return;
OrderCount++;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
@@ -66,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
public bool HasPrerequisites(IEnumerable<string> prerequisites)
{
var ownedPrereqs = GatherOwnedPrerequisites(Owner);
return prerequisites.All(p => !(p.Replace("~", "").StartsWith("!", StringComparison.Ordinal)
return prerequisites.All(p => !(p.Replace("~", "").StartsWith('!')
^ !ownedPrereqs.ContainsKey(p.Replace("!", "").Replace("~", ""))));
}
@@ -142,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var prereq in prerequisites)
{
var withoutTilde = prereq.Replace("~", "");
if (withoutTilde.StartsWith("!", StringComparison.Ordinal) ^ !ownedPrerequisites.ContainsKey(withoutTilde.Replace("!", "")))
if (withoutTilde.StartsWith('!') ^ !ownedPrerequisites.ContainsKey(withoutTilde.Replace("!", "")))
return false;
}
@@ -154,10 +153,10 @@ namespace OpenRA.Mods.Common.Traits
// PERF: Avoid LINQ.
foreach (var prereq in prerequisites)
{
if (!prereq.StartsWith("~", StringComparison.Ordinal))
if (!prereq.StartsWith('~'))
continue;
var withoutTilde = prereq.Replace("~", "");
if (withoutTilde.StartsWith("!", StringComparison.Ordinal) ^ !ownedPrerequisites.ContainsKey(withoutTilde.Replace("!", "")))
if (withoutTilde.StartsWith('!') ^ !ownedPrerequisites.ContainsKey(withoutTilde.Replace("!", "")))
return true;
}

View File

@@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Traits
void SyncMultiplayerCount()
{
var newCount = previews.Count(p => p.Info.Name == "mpspawn");
var mp = Players.Players.Where(p => p.Key.StartsWith("Multi")).ToList();
var mp = Players.Players.Where(p => p.Key.StartsWith("Multi", StringComparison.Ordinal)).ToList();
foreach (var kv in mp)
{
var name = kv.Key;

View File

@@ -192,7 +192,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
defaultTilesetFilenamesNode = defaultsNode.LastChildMatching("TilesetFilenames") ?? defaultTilesetFilenamesNode;
}
if ((defaultFilenameNode == null || defaultTilesetFilenamesNode == null) && !imageNode.Key.StartsWith("^"))
if ((defaultFilenameNode == null || defaultTilesetFilenamesNode == null) && !imageNode.Key.StartsWith('^'))
{
var duplicateCount = new Dictionary<string, int>();
var duplicateTilesetCount = new Dictionary<string, int>();
@@ -372,7 +372,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
// Replace removals with masking
foreach (var node in sequenceNode.Value.Nodes)
if (node.Key?.StartsWith("-") ?? false)
if (node.Key?.StartsWith('-') ?? false)
node.Key = node.Key[1..];
var combineNode = sequenceNode.LastChildMatching("Combine");
@@ -389,7 +389,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
}
var filename = string.IsNullOrEmpty(resolvedSequenceNode.Value.Value) ? imageName : resolvedSequenceNode.Value.Value;
if (filename.StartsWith("^"))
if (filename.StartsWith('^'))
return;
if (useTilesetExtension || useTilesetCode)

View File

@@ -46,7 +46,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
var interfaceMembers = interfaceType.GetMembers();
foreach (var interfaceMember in interfaceMembers)
{
if (interfaceMember.Name.StartsWith("get_") || interfaceMember.Name.StartsWith("set_") || interfaceMember.Name.StartsWith("add_") || interfaceMember.Name.StartsWith("remove_"))
if (interfaceMember.Name.StartsWith("get_", StringComparison.Ordinal) ||
interfaceMember.Name.StartsWith("set_", StringComparison.Ordinal) ||
interfaceMember.Name.StartsWith("add_", StringComparison.Ordinal) ||
interfaceMember.Name.StartsWith("remove_", StringComparison.Ordinal))
continue;
var interfaceMethod = interfaceMember as MethodInfo;

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
var value = field.GetValue(section.Value);
if (value != null && !value.ToString().StartsWith("System."))
if (value != null && !value.ToString().StartsWith("System.", StringComparison.Ordinal))
{
Console.WriteLine($"**Default Value:** {value}");
Console.WriteLine();

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
.Select(type => new
{
type.Namespace,
Name = type.Name.EndsWith("Info") ? type.Name[..^4] : type.Name,
Name = type.Name.EndsWith("Info", StringComparison.Ordinal) ? type.Name[..^4] : type.Name,
Description = string.Join(" ", Utility.GetCustomAttributes<DescAttribute>(type, false).SelectMany(d => d.Lines)),
RequiresTraits = RequiredTraitTypes(type)
.Select(y => y.Name),
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
.Select(a =>
{
var name = a.AttributeType.Name;
name = name.EndsWith("Attribute") ? name[..^9] : name;
name = name.EndsWith("Attribute", StringComparison.Ordinal) ? name[..^9] : name;
return new
{

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
.Select(type => new
{
type.Namespace,
Name = type.Name.EndsWith("Info") ? type.Name[..^4] : type.Name,
Name = type.Name.EndsWith("Info", StringComparison.Ordinal) ? type.Name[..^4] : type.Name,
Description = string.Join(" ", Utility.GetCustomAttributes<DescAttribute>(type, false).SelectMany(d => d.Lines)),
InheritedTypes = type.BaseTypes()
.Select(y => y.Name)
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
.Select(a =>
{
var name = a.AttributeType.Name;
name = name.EndsWith("Attribute") ? name[..^9] : name;
name = name.EndsWith("Attribute", StringComparison.Ordinal) ? name[..^9] : name;
return new
{

View File

@@ -150,7 +150,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (buildable != null)
{
var prerequisites = buildable.Prerequisites.Select(a => ActorName(modData.DefaultRules, a))
.Where(s => !s.StartsWith("~", StringComparison.Ordinal) && !s.StartsWith("!", StringComparison.Ordinal));
.Where(s => !s.StartsWith('~') && !s.StartsWith('!'));
if (prerequisites.Any())
text += $"Requires {prerequisites.JoinWith(", ")}\n\n";
}

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Commands;
@@ -143,7 +142,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var team = teamChat && !disableTeamChat;
if (chatText.Text != "")
{
if (!chatText.Text.StartsWith("/", StringComparison.Ordinal))
if (!chatText.Text.StartsWith('/'))
{
// This should never happen, but avoid a crash if it does somehow (chat will just stay open)
if (!isObserver && orderManager.LocalClient == null && world.LocalPlayer == null)

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a))
.Where(s => !s.StartsWith("~", StringComparison.Ordinal) && !s.StartsWith("!", StringComparison.Ordinal));
.Where(s => !s.StartsWith('~') && !s.StartsWith('!'));
var requiresSize = int2.Zero;
if (prereqs.Any())

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
var toComplete = "";
if (text.StartsWith("/") && Commands != null)
if (text.StartsWith('/') && Commands != null)
{
prefix = "/";
suffix = "";

View File

@@ -209,7 +209,7 @@ namespace OpenRA.Platforms.Default
var lines = p.StandardOutput.ReadToEnd().Split('\n');
foreach (var line in lines)
if (line.StartsWith("Xft.dpi") && int.TryParse(line.AsSpan(8), out var dpi))
if (line.StartsWith("Xft.dpi", StringComparison.Ordinal) && int.TryParse(line.AsSpan(8), out var dpi))
windowScale = dpi / 96f;
}
catch { }