Fix IDE0251

This commit is contained in:
RoosterDragon
2023-08-10 18:50:20 +01:00
committed by abcdefg30
parent 3b2fad6ea8
commit a1dfb42812
10 changed files with 41 additions and 37 deletions

View File

@@ -333,6 +333,10 @@ dotnet_diagnostic.IDE0064.severity = warning
#csharp_style_prefer_readonly_struct = true #csharp_style_prefer_readonly_struct = true
dotnet_diagnostic.IDE0250.severity = warning dotnet_diagnostic.IDE0250.severity = warning
# IDE0251 Member can be made 'readonly'
#csharp_style_prefer_readonly_struct_member = true
dotnet_diagnostic.IDE0251.severity = warning
## Null-checking preferences ## Null-checking preferences
# IDE1005 Use conditional delegate call # IDE1005 Use conditional delegate call

View File

@@ -600,7 +600,7 @@ namespace OpenRA
Current = default; Current = default;
} }
public LineSplitEnumerator GetEnumerator() => this; public readonly LineSplitEnumerator GetEnumerator() => this;
public bool MoveNext() public bool MoveNext()
{ {

View File

@@ -162,8 +162,8 @@ namespace OpenRA
} }
public CPos Current { get; private set; } public CPos Current { get; private set; }
object IEnumerator.Current => Current; readonly object IEnumerator.Current => Current;
public void Dispose() { } public readonly void Dispose() { }
} }
} }
} }

View File

@@ -53,8 +53,8 @@ namespace OpenRA
} }
public MPos Current { get; private set; } public MPos Current { get; private set; }
object IEnumerator.Current => Current; readonly object IEnumerator.Current => Current;
public void Dispose() { } public readonly void Dispose() { }
} }
public MapCoordsRegion(MPos mapTopLeft, MPos mapBottomRight) public MapCoordsRegion(MPos mapTopLeft, MPos mapBottomRight)

View File

@@ -118,8 +118,8 @@ namespace OpenRA
} }
public PPos Current { get; private set; } public PPos Current { get; private set; }
object IEnumerator.Current => Current; readonly object IEnumerator.Current => Current;
public void Dispose() { } public readonly void Dispose() { }
} }
} }
} }

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Network
public int Client; public int Client;
public Order Order; public Order Order;
public override string ToString() public override readonly string ToString()
{ {
return $"ClientId: {Client} {Order}"; return $"ClientId: {Client} {Order}";
} }

View File

@@ -300,7 +300,7 @@ namespace OpenRA.Network
public object this[int index] public object this[int index]
{ {
get readonly get
{ {
if (item2OrSentinel == Sentinel) if (item2OrSentinel == Sentinel)
return ((object[])item1OrArray)[index]; return ((object[])item1OrArray)[index];

View File

@@ -58,35 +58,35 @@ namespace OpenRA.Primitives
Height = size.Height; Height = size.Height;
} }
public int Left => X; public readonly int Left => X;
public int Right => X + Width; public readonly int Right => X + Width;
public int Top => Y; public readonly int Top => Y;
public int Bottom => Y + Height; public readonly int Bottom => Y + Height;
public bool IsEmpty => X == 0 && Y == 0 && Width == 0 && Height == 0; public readonly bool IsEmpty => X == 0 && Y == 0 && Width == 0 && Height == 0;
public int2 Location => new(X, Y); public readonly int2 Location => new(X, Y);
public Size Size => new(Width, Height); public readonly Size Size => new(Width, Height);
public int2 TopLeft => Location; public readonly int2 TopLeft => Location;
public int2 TopRight => new(X + Width, Y); public readonly int2 TopRight => new(X + Width, Y);
public int2 BottomLeft => new(X, Y + Height); public readonly int2 BottomLeft => new(X, Y + Height);
public int2 BottomRight => new(X + Width, Y + Height); public readonly int2 BottomRight => new(X + Width, Y + Height);
public bool Contains(int x, int y) public readonly bool Contains(int x, int y)
{ {
return x >= Left && x < Right && y >= Top && y < Bottom; return x >= Left && x < Right && y >= Top && y < Bottom;
} }
public bool Contains(int2 pt) public readonly bool Contains(int2 pt)
{ {
return Contains(pt.X, pt.Y); return Contains(pt.X, pt.Y);
} }
public bool Equals(Rectangle other) public readonly bool Equals(Rectangle other)
{ {
return this == other; return this == other;
} }
public override bool Equals(object obj) public override readonly bool Equals(object obj)
{ {
if (obj is not Rectangle) if (obj is not Rectangle)
return false; return false;
@@ -94,17 +94,17 @@ namespace OpenRA.Primitives
return this == (Rectangle)obj; return this == (Rectangle)obj;
} }
public override int GetHashCode() public override readonly int GetHashCode()
{ {
return Height + Width ^ X + Y; return Height + Width ^ X + Y;
} }
public bool IntersectsWith(Rectangle rect) public readonly bool IntersectsWith(Rectangle rect)
{ {
return Left < rect.Right && Right > rect.Left && Top < rect.Bottom && Bottom > rect.Top; return Left < rect.Right && Right > rect.Left && Top < rect.Bottom && Bottom > rect.Top;
} }
bool IntersectsWithInclusive(Rectangle r) readonly bool IntersectsWithInclusive(Rectangle r)
{ {
return Left <= r.Right && Right >= r.Left && Top <= r.Bottom && Bottom >= r.Top; return Left <= r.Right && Right >= r.Left && Top <= r.Bottom && Bottom >= r.Top;
} }
@@ -117,14 +117,14 @@ namespace OpenRA.Primitives
return FromLTRB(Math.Max(a.Left, b.Left), Math.Max(a.Top, b.Top), Math.Min(a.Right, b.Right), Math.Min(a.Bottom, b.Bottom)); return FromLTRB(Math.Max(a.Left, b.Left), Math.Max(a.Top, b.Top), Math.Min(a.Right, b.Right), Math.Min(a.Bottom, b.Bottom));
} }
public bool Contains(Rectangle rect) public readonly bool Contains(Rectangle rect)
{ {
return rect == Intersect(this, rect); return rect == Intersect(this, rect);
} }
public static Rectangle operator *(int a, Rectangle b) { return new Rectangle(a * b.X, a * b.Y, a * b.Width, a * b.Height); } public static Rectangle operator *(int a, Rectangle b) { return new Rectangle(a * b.X, a * b.Y, a * b.Width, a * b.Height); }
public override string ToString() public override readonly string ToString()
{ {
return $"{X},{Y},{Width},{Height}"; return $"{X},{Y},{Width},{Height}";
} }

View File

@@ -210,9 +210,9 @@ namespace OpenRA
public void Reset() { index = actors.BinarySearchMany(actor) - 1; } public void Reset() { index = actors.BinarySearchMany(actor) - 1; }
public bool MoveNext() { return ++index < actors.Count && actors[index].ActorID == actor; } public bool MoveNext() { return ++index < actors.Count && actors[index].ActorID == actor; }
public T Current => traits[index]; public readonly T Current => traits[index];
object System.Collections.IEnumerator.Current => Current; readonly object System.Collections.IEnumerator.Current => Current;
public void Dispose() { } public readonly void Dispose() { }
} }
public IEnumerable<TraitPair<T>> All() public IEnumerable<TraitPair<T>> All()
@@ -276,9 +276,9 @@ namespace OpenRA
public void Reset() { index = -1; } public void Reset() { index = -1; }
public bool MoveNext() { return ++index < actors.Count; } public bool MoveNext() { return ++index < actors.Count; }
public TraitPair<T> Current => new(actors[index], traits[index]); public readonly TraitPair<T> Current => new(actors[index], traits[index]);
object System.Collections.IEnumerator.Current => Current; readonly object System.Collections.IEnumerator.Current => Current;
public void Dispose() { } public readonly void Dispose() { }
} }
public void RemoveActor(uint actor) public void RemoveActor(uint actor)

View File

@@ -239,8 +239,8 @@ namespace OpenRA.Mods.Common.Traits
public void Reset() { throw new NotSupportedException(); } public void Reset() { throw new NotSupportedException(); }
public Actor Current { get; private set; } public Actor Current { get; private set; }
object IEnumerator.Current => Current; readonly object IEnumerator.Current => Current;
public void Dispose() { } public readonly void Dispose() { }
public bool MoveNext() public bool MoveNext()
{ {
while (node != null) while (node != null)