Fix IDE0056
This commit is contained in:
committed by
Pavel Penev
parent
4ec5a4b34a
commit
5254348819
@@ -141,7 +141,7 @@ dotnet_diagnostic.IDE0074.severity = silent # Requires C# 8 - TODO Consider enab
|
||||
|
||||
# IDE0056 Use index operator
|
||||
#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
|
||||
#csharp_style_prefer_range_operator = true
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace OpenRA.Graphics
|
||||
// Segment is part of closed loop
|
||||
if (closed)
|
||||
{
|
||||
var prev = points[points.Length - 1];
|
||||
var prev = points[^1];
|
||||
var prevDir = (start - prev) / (start - prev).XY.Length;
|
||||
var prevCorner = width / 2 * new float3(-prevDir.Y, prevDir.X, prevDir.Z);
|
||||
ca = IntersectionOf(start - prevCorner, prevDir, start - corner, dir);
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace OpenRA
|
||||
|
||||
while (levels.Count > level + 1)
|
||||
{
|
||||
levels[levels.Count - 1].TrimExcess();
|
||||
levels[^1].TrimExcess();
|
||||
levels.RemoveAt(levels.Count - 1);
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ namespace OpenRA
|
||||
{
|
||||
// Remove leading/trailing whitespace guards
|
||||
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)
|
||||
value = value.Slice(trimLeading, value.Length - trimLeading - trimTrailing);
|
||||
|
||||
|
||||
@@ -719,12 +719,12 @@ namespace OpenRA.Support
|
||||
readonly List<Expression> expressions = new List<Expression>();
|
||||
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)
|
||||
{
|
||||
var fromType = types[types.Count - 1];
|
||||
var expression = expressions[expressions.Count - 1];
|
||||
var fromType = types[^1];
|
||||
var expression = expressions[^1];
|
||||
if (toType == fromType)
|
||||
return expression;
|
||||
|
||||
|
||||
@@ -73,13 +73,13 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
parts.Insert(0, "." + Path.DirectorySeparatorChar);
|
||||
|
||||
// If the last entry ends with a directory separator, append a '*'
|
||||
if (parts[parts.Count - 1][parts[parts.Count - 1].Length - 1] == Path.DirectorySeparatorChar
|
||||
|| parts[parts.Count - 1][parts[parts.Count - 1].Length - 1] == Path.AltDirectorySeparatorChar)
|
||||
if (parts[^1][^1] == Path.DirectorySeparatorChar
|
||||
|| parts[^1][^1] == Path.AltDirectorySeparatorChar)
|
||||
parts.Add("*");
|
||||
|
||||
var root = parts[0];
|
||||
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))
|
||||
yield return path;
|
||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
}
|
||||
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);
|
||||
foreach (var subDir in Directory.EnumerateDirectories(basePath, dir, SearchOption.TopDirectoryOnly))
|
||||
foreach (var s in Expand(subDir, dirs, dirIndex + 1, file))
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (path.Count == 0)
|
||||
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.
|
||||
if (!Util.AreAdjacentCells(mobile.ToCell, nextCell))
|
||||
@@ -280,7 +280,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (newPath.Count != 0)
|
||||
{
|
||||
path = newPath;
|
||||
var newCell = path[path.Count - 1];
|
||||
var newCell = path[^1];
|
||||
path.RemoveAt(path.Count - 1);
|
||||
|
||||
return (newCell, mobile.GetAvailableSubCell(nextCell, mobile.FromSubCell, ignoreActor));
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.HitShapes
|
||||
combatOverlayVertsTop = Points.Select(p => new WVec(p.X, p.Y, VerticalTopOffset)).ToArray();
|
||||
combatOverlayVertsBottom = Points.Select(p => new WVec(p.X, p.Y, VerticalBottomOffset)).ToArray();
|
||||
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++)
|
||||
squares[i] = (Points[i] - Points[i - 1]).LengthSquared;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.HitShapes
|
||||
if (Points.PolygonContains(p))
|
||||
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++)
|
||||
{
|
||||
var d2 = DistanceSquaredFromLineSegment(p, Points[i - 1], Points[i], squares[i]);
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
shotsFired++;
|
||||
var requiredShots = tokens.Count < Info.RequiredShotsPerInstance.Length
|
||||
? Info.RequiredShotsPerInstance[tokens.Count]
|
||||
: Info.RequiredShotsPerInstance[Info.RequiredShotsPerInstance.Length - 1];
|
||||
: Info.RequiredShotsPerInstance[^1];
|
||||
|
||||
if (shotsFired >= requiredShots)
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly Color Color;
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common
|
||||
}
|
||||
|
||||
if (items.Length > 0)
|
||||
yield return items[items.Length - 1];
|
||||
yield return items[^1];
|
||||
}
|
||||
|
||||
static IEnumerable<CPos> Neighbours(CPos c, bool allowDiagonal)
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
if (args.Contains("--noshadow"))
|
||||
{
|
||||
Array.Resize(ref shadowIndex, shadowIndex.Length + 3);
|
||||
shadowIndex[shadowIndex.Length - 1] = 1;
|
||||
shadowIndex[shadowIndex.Length - 2] = 3;
|
||||
shadowIndex[shadowIndex.Length - 3] = 4;
|
||||
shadowIndex[^1] = 1;
|
||||
shadowIndex[^2] = 3;
|
||||
shadowIndex[^3] = 4;
|
||||
}
|
||||
|
||||
var palette = new ImmutablePalette(args[2], new[] { 0 }, shadowIndex);
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
if (debugVis != null && debugVis.CombatGeometry)
|
||||
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))
|
||||
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.
|
||||
if (falloffDistance > effectiveRange[effectiveRange.Length - 1].Length)
|
||||
if (falloffDistance > effectiveRange[^1].Length)
|
||||
continue;
|
||||
|
||||
var localModifiers = args.DamageModifiers.Append(GetDamageFalloff(falloffDistance));
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (!IsVisible() || Children.Count == 0)
|
||||
return;
|
||||
|
||||
var mostRecentMessageOverflows = Bounds.Height < Children[Children.Count - 1].Bounds.Height;
|
||||
var mostRecentMessageOverflows = Bounds.Height < Children[^1].Bounds.Height;
|
||||
|
||||
if (mostRecentMessageOverflows && HideOverflow)
|
||||
Game.Renderer.EnableScissor(overflowDrawBounds);
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
foreach (var line in Children)
|
||||
line.Bounds.Y -= notificationWidget.Bounds.Height + ItemSpacing;
|
||||
|
||||
var lastLine = Children[Children.Count - 1];
|
||||
var lastLine = Children[^1];
|
||||
notificationWidget.Bounds.Y = lastLine.Bounds.Bottom + ItemSpacing;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (Children.Count == 0)
|
||||
return;
|
||||
|
||||
var mostRecentChild = Children[Children.Count - 1];
|
||||
var mostRecentChild = Children[^1];
|
||||
|
||||
RemoveChild(mostRecentChild);
|
||||
expirations.RemoveAt(expirations.Count - 1);
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.D2k.Traits
|
||||
var length = distance.Length;
|
||||
|
||||
// Actor is too far to hear anything.
|
||||
if (length > effectiveRange[effectiveRange.Length - 1].Length)
|
||||
if (length > effectiveRange[^1].Length)
|
||||
return WVec.Zero;
|
||||
|
||||
var direction = 1024 * distance / length;
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace OpenRA
|
||||
return;
|
||||
|
||||
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}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user