diff --git a/.editorconfig b/.editorconfig index c09da4d9cd..258b98da29 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1043,6 +1043,9 @@ dotnet_diagnostic.CA2251.severity = warning # Ensure ThreadStatic is only used with static fields. dotnet_diagnostic.CA2259.severity = suggestion # TODO: Change to warning once using .NET 7 or later. +# Prefer generic overload when type is known. +dotnet_diagnostic.CA2263.severity = none # TODO: Change to warning once mono is dropped. + # Do not pass a non-nullable value to 'ArgumentNullException.ThrowIfNull'. dotnet_diagnostic.CA2264.severity = warning diff --git a/OpenRA.Game/Graphics/SpriteRenderer.cs b/OpenRA.Game/Graphics/SpriteRenderer.cs index 1ec75cb97f..0c34ee2080 100644 --- a/OpenRA.Game/Graphics/SpriteRenderer.cs +++ b/OpenRA.Game/Graphics/SpriteRenderer.cs @@ -20,7 +20,7 @@ namespace OpenRA.Graphics { public const int SheetCount = 8; static readonly string[] SheetIndexToTextureName = Exts.MakeArray(SheetCount, i => $"Texture{i}"); - static readonly int UintSize = Marshal.SizeOf(typeof(uint)); + static readonly int UintSize = Marshal.SizeOf(); readonly Renderer renderer; readonly IShader shader; diff --git a/OpenRA.Game/Map/ActorInitializer.cs b/OpenRA.Game/Map/ActorInitializer.cs index 774aab4094..7382fca43a 100644 --- a/OpenRA.Game/Map/ActorInitializer.cs +++ b/OpenRA.Game/Map/ActorInitializer.cs @@ -154,7 +154,7 @@ namespace OpenRA public virtual void Initialize(MiniYaml yaml) { - Initialize((T)FieldLoader.GetValue(nameof(value), typeof(T), yaml.Value)); + Initialize(FieldLoader.GetValue(nameof(value), yaml.Value)); } public virtual void Initialize(T value) diff --git a/OpenRA.Mods.Common/ActorInitializer.cs b/OpenRA.Mods.Common/ActorInitializer.cs index e528321faa..3281903381 100644 --- a/OpenRA.Mods.Common/ActorInitializer.cs +++ b/OpenRA.Mods.Common/ActorInitializer.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common public void Initialize(MiniYaml yaml) { - Initialize((int)FieldLoader.GetValue(nameof(value), typeof(int), yaml.Value)); + Initialize(FieldLoader.GetValue(nameof(value), yaml.Value)); } public void Initialize(int value) diff --git a/OpenRA.Platforms.Default/Sdl2HardwareCursor.cs b/OpenRA.Platforms.Default/Sdl2HardwareCursor.cs index f34b6f5ab1..921d62f5a9 100644 --- a/OpenRA.Platforms.Default/Sdl2HardwareCursor.cs +++ b/OpenRA.Platforms.Default/Sdl2HardwareCursor.cs @@ -30,7 +30,7 @@ namespace OpenRA.Platforms.Default if (surface == IntPtr.Zero) throw new InvalidDataException($"Failed to create surface: {SDL.SDL_GetError()}"); - var sur = (SDL.SDL_Surface)Marshal.PtrToStructure(surface, typeof(SDL.SDL_Surface)); + var sur = Marshal.PtrToStructure(surface); Marshal.Copy(data, 0, sur.pixels, data.Length); // This call very occasionally fails on Windows, but often works when retried. diff --git a/OpenRA.Platforms.Default/VertexBuffer.cs b/OpenRA.Platforms.Default/VertexBuffer.cs index 16fe21b083..183cbe8be6 100644 --- a/OpenRA.Platforms.Default/VertexBuffer.cs +++ b/OpenRA.Platforms.Default/VertexBuffer.cs @@ -17,7 +17,7 @@ namespace OpenRA.Platforms.Default sealed class VertexBuffer : ThreadAffine, IDisposable, IVertexBuffer where T : struct { - static readonly int VertexSize = Marshal.SizeOf(typeof(T)); + static readonly int VertexSize = Marshal.SizeOf(); uint buffer; bool disposed;