Fix IDE0056

This commit is contained in:
RoosterDragon
2023-04-05 19:09:23 +01:00
committed by Pavel Penev
parent 4ec5a4b34a
commit 5254348819
15 changed files with 28 additions and 28 deletions

View File

@@ -141,7 +141,7 @@ dotnet_diagnostic.IDE0074.severity = silent # Requires C# 8 - TODO Consider enab
# IDE0056 Use index operator # IDE0056 Use index operator
#csharp_style_prefer_index_operator = true #csharp_style_prefer_index_operator = true
dotnet_diagnostic.IDE0056.severity = silent # Requires C# 8 - TODO Consider enabling dotnet_diagnostic.IDE0056.severity = warning
# IDE0057 Use range operator # IDE0057 Use range operator
#csharp_style_prefer_range_operator = true #csharp_style_prefer_range_operator = true

View File

@@ -138,7 +138,7 @@ namespace OpenRA.Graphics
// Segment is part of closed loop // Segment is part of closed loop
if (closed) if (closed)
{ {
var prev = points[points.Length - 1]; var prev = points[^1];
var prevDir = (start - prev) / (start - prev).XY.Length; var prevDir = (start - prev) / (start - prev).XY.Length;
var prevCorner = width / 2 * new float3(-prevDir.Y, prevDir.X, prevDir.Z); var prevCorner = width / 2 * new float3(-prevDir.Y, prevDir.X, prevDir.Z);
ca = IntersectionOf(start - prevCorner, prevDir, start - corner, dir); ca = IntersectionOf(start - prevCorner, prevDir, start - corner, dir);

View File

@@ -209,7 +209,7 @@ namespace OpenRA
while (levels.Count > level + 1) while (levels.Count > level + 1)
{ {
levels[levels.Count - 1].TrimExcess(); levels[^1].TrimExcess();
levels.RemoveAt(levels.Count - 1); levels.RemoveAt(levels.Count - 1);
} }
@@ -260,7 +260,7 @@ namespace OpenRA
{ {
// Remove leading/trailing whitespace guards // Remove leading/trailing whitespace guards
var trimLeading = value[0] == '\\' && (value[1] == ' ' || value[1] == '\t') ? 1 : 0; var trimLeading = value[0] == '\\' && (value[1] == ' ' || value[1] == '\t') ? 1 : 0;
var trimTrailing = value[value.Length - 1] == '\\' && (value[value.Length - 2] == ' ' || value[value.Length - 2] == '\t') ? 1 : 0; var trimTrailing = value[^1] == '\\' && (value[^2] == ' ' || value[^2] == '\t') ? 1 : 0;
if (trimLeading + trimTrailing > 0) if (trimLeading + trimTrailing > 0)
value = value.Slice(trimLeading, value.Length - trimLeading - trimTrailing); value = value.Slice(trimLeading, value.Length - trimLeading - trimTrailing);

View File

@@ -719,12 +719,12 @@ namespace OpenRA.Support
readonly List<Expression> expressions = new List<Expression>(); readonly List<Expression> expressions = new List<Expression>();
readonly List<ExpressionType> types = new List<ExpressionType>(); readonly List<ExpressionType> types = new List<ExpressionType>();
public ExpressionType PeekType() { return types[types.Count - 1]; } public ExpressionType PeekType() { return types[^1]; }
public Expression Peek(ExpressionType toType) public Expression Peek(ExpressionType toType)
{ {
var fromType = types[types.Count - 1]; var fromType = types[^1];
var expression = expressions[expressions.Count - 1]; var expression = expressions[^1];
if (toType == fromType) if (toType == fromType)
return expression; return expression;

View File

@@ -73,13 +73,13 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
parts.Insert(0, "." + Path.DirectorySeparatorChar); parts.Insert(0, "." + Path.DirectorySeparatorChar);
// If the last entry ends with a directory separator, append a '*' // If the last entry ends with a directory separator, append a '*'
if (parts[parts.Count - 1][parts[parts.Count - 1].Length - 1] == Path.DirectorySeparatorChar if (parts[^1][^1] == Path.DirectorySeparatorChar
|| parts[parts.Count - 1][parts[parts.Count - 1].Length - 1] == Path.AltDirectorySeparatorChar) || parts[^1][^1] == Path.AltDirectorySeparatorChar)
parts.Add("*"); parts.Add("*");
var root = parts[0]; var root = parts[0];
var dirs = parts.Skip(1).Take(parts.Count - 2).ToList(); var dirs = parts.Skip(1).Take(parts.Count - 2).ToList();
var file = parts[parts.Count - 1]; var file = parts[^1];
foreach (var path in Expand(root, dirs, 0, file)) foreach (var path in Expand(root, dirs, 0, file))
yield return path; yield return path;
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
} }
else else
{ {
if (dir[dir.Length - 1] == Path.DirectorySeparatorChar || dir[dir.Length - 1] == Path.AltDirectorySeparatorChar) if (dir[^1] == Path.DirectorySeparatorChar || dir[^1] == Path.AltDirectorySeparatorChar)
dir = dir.Substring(0, dir.Length - 1); dir = dir.Substring(0, dir.Length - 1);
foreach (var subDir in Directory.EnumerateDirectories(basePath, dir, SearchOption.TopDirectoryOnly)) foreach (var subDir in Directory.EnumerateDirectories(basePath, dir, SearchOption.TopDirectoryOnly))
foreach (var s in Expand(subDir, dirs, dirIndex + 1, file)) foreach (var s in Expand(subDir, dirs, dirIndex + 1, file))

View File

@@ -202,7 +202,7 @@ namespace OpenRA.Mods.Common.Activities
if (path.Count == 0) if (path.Count == 0)
return null; return null;
var nextCell = path[path.Count - 1]; var nextCell = path[^1];
// Something else might have moved us, so the path is no longer valid. // Something else might have moved us, so the path is no longer valid.
if (!Util.AreAdjacentCells(mobile.ToCell, nextCell)) if (!Util.AreAdjacentCells(mobile.ToCell, nextCell))
@@ -280,7 +280,7 @@ namespace OpenRA.Mods.Common.Activities
if (newPath.Count != 0) if (newPath.Count != 0)
{ {
path = newPath; path = newPath;
var newCell = path[path.Count - 1]; var newCell = path[^1];
path.RemoveAt(path.Count - 1); path.RemoveAt(path.Count - 1);
return (newCell, mobile.GetAvailableSubCell(nextCell, mobile.FromSubCell, ignoreActor)); return (newCell, mobile.GetAvailableSubCell(nextCell, mobile.FromSubCell, ignoreActor));

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.HitShapes
combatOverlayVertsTop = Points.Select(p => new WVec(p.X, p.Y, VerticalTopOffset)).ToArray(); combatOverlayVertsTop = Points.Select(p => new WVec(p.X, p.Y, VerticalTopOffset)).ToArray();
combatOverlayVertsBottom = Points.Select(p => new WVec(p.X, p.Y, VerticalBottomOffset)).ToArray(); combatOverlayVertsBottom = Points.Select(p => new WVec(p.X, p.Y, VerticalBottomOffset)).ToArray();
squares = new int[Points.Length]; squares = new int[Points.Length];
squares[0] = (Points[0] - Points[Points.Length - 1]).LengthSquared; squares[0] = (Points[0] - Points[^1]).LengthSquared;
for (var i = 1; i < Points.Length; i++) for (var i = 1; i < Points.Length; i++)
squares[i] = (Points[i] - Points[i - 1]).LengthSquared; squares[i] = (Points[i] - Points[i - 1]).LengthSquared;
} }
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.HitShapes
if (Points.PolygonContains(p)) if (Points.PolygonContains(p))
return new WDist(z); return new WDist(z);
var min2 = DistanceSquaredFromLineSegment(p, Points[Points.Length - 1], Points[0], squares[0]); var min2 = DistanceSquaredFromLineSegment(p, Points[^1], Points[0], squares[0]);
for (var i = 1; i < Points.Length; i++) for (var i = 1; i < Points.Length; i++)
{ {
var d2 = DistanceSquaredFromLineSegment(p, Points[i - 1], Points[i], squares[i]); var d2 = DistanceSquaredFromLineSegment(p, Points[i - 1], Points[i], squares[i]);

View File

@@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Traits
shotsFired++; shotsFired++;
var requiredShots = tokens.Count < Info.RequiredShotsPerInstance.Length var requiredShots = tokens.Count < Info.RequiredShotsPerInstance.Length
? Info.RequiredShotsPerInstance[tokens.Count] ? Info.RequiredShotsPerInstance[tokens.Count]
: Info.RequiredShotsPerInstance[Info.RequiredShotsPerInstance.Length - 1]; : Info.RequiredShotsPerInstance[^1];
if (shotsFired >= requiredShots) if (shotsFired >= requiredShots)
{ {

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly Color Color; public readonly Color Color;
public int Time; public int Time;
public WDist OuterRange => Range[Range.Length - 1]; public WDist OuterRange => Range[^1];
public WHImpact(WPos pos, WDist[] range, int time, Color color) public WHImpact(WPos pos, WDist[] range, int time, Color color)
{ {

View File

@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common
} }
if (items.Length > 0) if (items.Length > 0)
yield return items[items.Length - 1]; yield return items[^1];
} }
static IEnumerable<CPos> Neighbours(CPos c, bool allowDiagonal) static IEnumerable<CPos> Neighbours(CPos c, bool allowDiagonal)

View File

@@ -39,9 +39,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (args.Contains("--noshadow")) if (args.Contains("--noshadow"))
{ {
Array.Resize(ref shadowIndex, shadowIndex.Length + 3); Array.Resize(ref shadowIndex, shadowIndex.Length + 3);
shadowIndex[shadowIndex.Length - 1] = 1; shadowIndex[^1] = 1;
shadowIndex[shadowIndex.Length - 2] = 3; shadowIndex[^2] = 3;
shadowIndex[shadowIndex.Length - 3] = 4; shadowIndex[^3] = 4;
} }
var palette = new ImmutablePalette(args[2], new[] { 0 }, shadowIndex); var palette = new ImmutablePalette(args[2], new[] { 0 }, shadowIndex);

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Warheads
if (debugVis != null && debugVis.CombatGeometry) if (debugVis != null && debugVis.CombatGeometry)
firedBy.World.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, effectiveRange, DebugOverlayColor); firedBy.World.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, effectiveRange, DebugOverlayColor);
foreach (var victim in firedBy.World.FindActorsOnCircle(pos, effectiveRange[effectiveRange.Length - 1])) foreach (var victim in firedBy.World.FindActorsOnCircle(pos, effectiveRange[^1]))
{ {
if (!IsValidAgainst(victim, firedBy)) if (!IsValidAgainst(victim, firedBy))
continue; continue;
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Warheads
} }
// The range to target is more than the range the warhead covers, so GetDamageFalloff() is going to give us 0 and we're going to do 0 damage anyway, so bail early. // The range to target is more than the range the warhead covers, so GetDamageFalloff() is going to give us 0 and we're going to do 0 damage anyway, so bail early.
if (falloffDistance > effectiveRange[effectiveRange.Length - 1].Length) if (falloffDistance > effectiveRange[^1].Length)
continue; continue;
var localModifiers = args.DamageModifiers.Append(GetDamageFalloff(falloffDistance)); var localModifiers = args.DamageModifiers.Append(GetDamageFalloff(falloffDistance));

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Widgets
if (!IsVisible() || Children.Count == 0) if (!IsVisible() || Children.Count == 0)
return; return;
var mostRecentMessageOverflows = Bounds.Height < Children[Children.Count - 1].Bounds.Height; var mostRecentMessageOverflows = Bounds.Height < Children[^1].Bounds.Height;
if (mostRecentMessageOverflows && HideOverflow) if (mostRecentMessageOverflows && HideOverflow)
Game.Renderer.EnableScissor(overflowDrawBounds); Game.Renderer.EnableScissor(overflowDrawBounds);
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Widgets
foreach (var line in Children) foreach (var line in Children)
line.Bounds.Y -= notificationWidget.Bounds.Height + ItemSpacing; line.Bounds.Y -= notificationWidget.Bounds.Height + ItemSpacing;
var lastLine = Children[Children.Count - 1]; var lastLine = Children[^1];
notificationWidget.Bounds.Y = lastLine.Bounds.Bottom + ItemSpacing; notificationWidget.Bounds.Y = lastLine.Bounds.Bottom + ItemSpacing;
} }
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Widgets
if (Children.Count == 0) if (Children.Count == 0)
return; return;
var mostRecentChild = Children[Children.Count - 1]; var mostRecentChild = Children[^1];
RemoveChild(mostRecentChild); RemoveChild(mostRecentChild);
expirations.RemoveAt(expirations.Count - 1); expirations.RemoveAt(expirations.Count - 1);

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Mods.D2k.Traits
var length = distance.Length; var length = distance.Length;
// Actor is too far to hear anything. // Actor is too far to hear anything.
if (length > effectiveRange[effectiveRange.Length - 1].Length) if (length > effectiveRange[^1].Length)
return WVec.Zero; return WVec.Zero;
var direction = 1024 * distance / length; var direction = 1024 * distance / length;

View File

@@ -169,7 +169,7 @@ namespace OpenRA
return; return;
var args = descParts.Take(descParts.Length - 1).JoinWith(" "); var args = descParts.Take(descParts.Length - 1).JoinWith(" ");
var desc = descParts[descParts.Length - 1]; var desc = descParts[^1];
Console.WriteLine($" {key} {args}{Environment.NewLine} {desc}{Environment.NewLine}"); Console.WriteLine($" {key} {args}{Environment.NewLine} {desc}{Environment.NewLine}");
} }