From a1dfb42812789a5035d22f5016dea671e97a1e91 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Thu, 10 Aug 2023 18:50:20 +0100 Subject: [PATCH] Fix IDE0251 --- .editorconfig | 4 +++ OpenRA.Game/Exts.cs | 2 +- OpenRA.Game/Map/CellRegion.cs | 4 +-- OpenRA.Game/Map/MapCoordsRegion.cs | 4 +-- OpenRA.Game/Map/ProjectedCellRegion.cs | 4 +-- OpenRA.Game/Network/OrderManager.cs | 2 +- OpenRA.Game/Network/SyncReport.cs | 2 +- OpenRA.Game/Primitives/Rectangle.cs | 40 ++++++++++----------- OpenRA.Game/TraitDictionary.cs | 12 +++---- OpenRA.Mods.Common/Traits/World/ActorMap.cs | 4 +-- 10 files changed, 41 insertions(+), 37 deletions(-) diff --git a/.editorconfig b/.editorconfig index 7e9a206b00..c4bb72adbe 100644 --- a/.editorconfig +++ b/.editorconfig @@ -333,6 +333,10 @@ dotnet_diagnostic.IDE0064.severity = warning #csharp_style_prefer_readonly_struct = true 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 # IDE1005 Use conditional delegate call diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 3186fbbfff..97a79ed0eb 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -600,7 +600,7 @@ namespace OpenRA Current = default; } - public LineSplitEnumerator GetEnumerator() => this; + public readonly LineSplitEnumerator GetEnumerator() => this; public bool MoveNext() { diff --git a/OpenRA.Game/Map/CellRegion.cs b/OpenRA.Game/Map/CellRegion.cs index 0beeb5b811..0f9fcb52de 100644 --- a/OpenRA.Game/Map/CellRegion.cs +++ b/OpenRA.Game/Map/CellRegion.cs @@ -162,8 +162,8 @@ namespace OpenRA } public CPos Current { get; private set; } - object IEnumerator.Current => Current; - public void Dispose() { } + readonly object IEnumerator.Current => Current; + public readonly void Dispose() { } } } } diff --git a/OpenRA.Game/Map/MapCoordsRegion.cs b/OpenRA.Game/Map/MapCoordsRegion.cs index bc76f64529..e77acd11c2 100644 --- a/OpenRA.Game/Map/MapCoordsRegion.cs +++ b/OpenRA.Game/Map/MapCoordsRegion.cs @@ -53,8 +53,8 @@ namespace OpenRA } public MPos Current { get; private set; } - object IEnumerator.Current => Current; - public void Dispose() { } + readonly object IEnumerator.Current => Current; + public readonly void Dispose() { } } public MapCoordsRegion(MPos mapTopLeft, MPos mapBottomRight) diff --git a/OpenRA.Game/Map/ProjectedCellRegion.cs b/OpenRA.Game/Map/ProjectedCellRegion.cs index 8978fda7fe..8f4c1d8b55 100644 --- a/OpenRA.Game/Map/ProjectedCellRegion.cs +++ b/OpenRA.Game/Map/ProjectedCellRegion.cs @@ -118,8 +118,8 @@ namespace OpenRA } public PPos Current { get; private set; } - object IEnumerator.Current => Current; - public void Dispose() { } + readonly object IEnumerator.Current => Current; + public readonly void Dispose() { } } } } diff --git a/OpenRA.Game/Network/OrderManager.cs b/OpenRA.Game/Network/OrderManager.cs index 0bce45df07..8a3c2ff229 100644 --- a/OpenRA.Game/Network/OrderManager.cs +++ b/OpenRA.Game/Network/OrderManager.cs @@ -70,7 +70,7 @@ namespace OpenRA.Network public int Client; public Order Order; - public override string ToString() + public override readonly string ToString() { return $"ClientId: {Client} {Order}"; } diff --git a/OpenRA.Game/Network/SyncReport.cs b/OpenRA.Game/Network/SyncReport.cs index 6b3874ba26..44aff3fa0f 100644 --- a/OpenRA.Game/Network/SyncReport.cs +++ b/OpenRA.Game/Network/SyncReport.cs @@ -300,7 +300,7 @@ namespace OpenRA.Network public object this[int index] { - get + readonly get { if (item2OrSentinel == Sentinel) return ((object[])item1OrArray)[index]; diff --git a/OpenRA.Game/Primitives/Rectangle.cs b/OpenRA.Game/Primitives/Rectangle.cs index 884c6eb69b..91a721feb6 100644 --- a/OpenRA.Game/Primitives/Rectangle.cs +++ b/OpenRA.Game/Primitives/Rectangle.cs @@ -58,35 +58,35 @@ namespace OpenRA.Primitives Height = size.Height; } - public int Left => X; - public int Right => X + Width; - public int Top => Y; - public int Bottom => Y + Height; - public bool IsEmpty => X == 0 && Y == 0 && Width == 0 && Height == 0; - public int2 Location => new(X, Y); - public Size Size => new(Width, Height); + public readonly int Left => X; + public readonly int Right => X + Width; + public readonly int Top => Y; + public readonly int Bottom => Y + Height; + public readonly bool IsEmpty => X == 0 && Y == 0 && Width == 0 && Height == 0; + public readonly int2 Location => new(X, Y); + public readonly Size Size => new(Width, Height); - public int2 TopLeft => Location; - public int2 TopRight => new(X + Width, Y); - public int2 BottomLeft => new(X, Y + Height); - public int2 BottomRight => new(X + Width, Y + Height); + public readonly int2 TopLeft => Location; + public readonly int2 TopRight => new(X + Width, Y); + public readonly int2 BottomLeft => new(X, 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; } - public bool Contains(int2 pt) + public readonly bool Contains(int2 pt) { return Contains(pt.X, pt.Y); } - public bool Equals(Rectangle other) + public readonly bool Equals(Rectangle other) { return this == other; } - public override bool Equals(object obj) + public override readonly bool Equals(object obj) { if (obj is not Rectangle) return false; @@ -94,17 +94,17 @@ namespace OpenRA.Primitives return this == (Rectangle)obj; } - public override int GetHashCode() + public override readonly int GetHashCode() { 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; } - bool IntersectsWithInclusive(Rectangle r) + readonly bool IntersectsWithInclusive(Rectangle r) { 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)); } - public bool Contains(Rectangle rect) + public readonly bool Contains(Rectangle 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 override string ToString() + public override readonly string ToString() { return $"{X},{Y},{Width},{Height}"; } diff --git a/OpenRA.Game/TraitDictionary.cs b/OpenRA.Game/TraitDictionary.cs index 6fb524a7a1..0a978eae2e 100644 --- a/OpenRA.Game/TraitDictionary.cs +++ b/OpenRA.Game/TraitDictionary.cs @@ -210,9 +210,9 @@ namespace OpenRA public void Reset() { index = actors.BinarySearchMany(actor) - 1; } public bool MoveNext() { return ++index < actors.Count && actors[index].ActorID == actor; } - public T Current => traits[index]; - object System.Collections.IEnumerator.Current => Current; - public void Dispose() { } + public readonly T Current => traits[index]; + readonly object System.Collections.IEnumerator.Current => Current; + public readonly void Dispose() { } } public IEnumerable> All() @@ -276,9 +276,9 @@ namespace OpenRA public void Reset() { index = -1; } public bool MoveNext() { return ++index < actors.Count; } - public TraitPair Current => new(actors[index], traits[index]); - object System.Collections.IEnumerator.Current => Current; - public void Dispose() { } + public readonly TraitPair Current => new(actors[index], traits[index]); + readonly object System.Collections.IEnumerator.Current => Current; + public readonly void Dispose() { } } public void RemoveActor(uint actor) diff --git a/OpenRA.Mods.Common/Traits/World/ActorMap.cs b/OpenRA.Mods.Common/Traits/World/ActorMap.cs index 595ec77a5f..7da45446d7 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorMap.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorMap.cs @@ -239,8 +239,8 @@ namespace OpenRA.Mods.Common.Traits public void Reset() { throw new NotSupportedException(); } public Actor Current { get; private set; } - object IEnumerator.Current => Current; - public void Dispose() { } + readonly object IEnumerator.Current => Current; + public readonly void Dispose() { } public bool MoveNext() { while (node != null)