Silence IDE0290.

This rule recommends use of primary constructors. Apply the suggestions on simple POCOs, adjusting some to readonly/structs/records at the same time. For more complex classes, the use of primary constructors is more distracting than helpful, so silence the rule. IDEs can still offer fixes for using primary constructors, but it will not show up as a build issue.
This commit is contained in:
RoosterDragon
2025-04-01 19:26:19 +01:00
committed by Gustas Kažukauskas
parent 3de6a5fd5a
commit 36660b89e9
52 changed files with 161 additions and 707 deletions

View File

@@ -72,7 +72,7 @@ dotnet_diagnostic.IDE0211.severity = warning
# IDE0290 Use primary constructor
#csharp_style_prefer_primary_constructors = true
dotnet_diagnostic.IDE0290.severity = suggestion # TODO: Consider enabling
dotnet_diagnostic.IDE0290.severity = silent
# IDE0330 Prefer 'System.Threading.Lock'
#csharp_prefer_system_threading_lock = true

View File

@@ -841,9 +841,8 @@ namespace OpenRA
// Mirrors DescriptionAttribute from System.ComponentModel but we don't want to have to use that everywhere.
[AttributeUsage(AttributeTargets.All)]
public sealed class DescAttribute : Attribute
public sealed class DescAttribute(params string[] lines) : Attribute
{
public readonly string[] Lines;
public DescAttribute(params string[] lines) { Lines = lines; }
public readonly string[] Lines = lines;
}
}

View File

@@ -37,19 +37,7 @@ namespace OpenRA.Graphics
Func<float> getScale, Func<IModel> getVoxel, Func<WRot> getRotation);
}
public readonly struct ModelRenderData
{
public readonly int Start;
public readonly int Count;
public readonly Sheet Sheet;
public ModelRenderData(int start, int count, Sheet sheet)
{
Start = start;
Count = count;
Sheet = sheet;
}
}
public readonly record struct ModelRenderData(int Start, int Count, Sheet Sheet);
public interface IModelCacheInfo : ITraitInfoInterface { }

View File

@@ -179,12 +179,6 @@ namespace OpenRA
TriangleList,
}
public readonly struct Range<T>
{
public readonly T Start, End;
public Range(T start, T end) { Start = start; End = end; }
}
public enum WindowMode
{
Windowed,

View File

@@ -14,29 +14,10 @@ using System.Runtime.InteropServices;
namespace OpenRA.Graphics
{
[StructLayout(LayoutKind.Sequential)]
public readonly struct RenderPostProcessPassVertex
{
public readonly float X, Y;
public RenderPostProcessPassVertex(float x, float y)
{
X = x; Y = y;
}
}
public readonly record struct RenderPostProcessPassVertex(float X, float Y);
[StructLayout(LayoutKind.Sequential)]
public readonly struct RenderPostProcessPassTexturedVertex
{
// 3d position
public readonly float X, Y;
public readonly float S, T;
public RenderPostProcessPassTexturedVertex(float x, float y, float s, float t)
{
X = x; Y = y;
S = s; T = t;
}
}
public readonly record struct RenderPostProcessPassTexturedVertex(float X, float Y, float S, float T);
public sealed class RenderPostProcessPassShaderBindings : ShaderBindings
{

View File

@@ -23,21 +23,7 @@ namespace OpenRA.Graphics
UInt = 0x1405 // GL_UNSIGNED_INT
}
public readonly struct ShaderVertexAttribute
{
public readonly string Name;
public readonly ShaderVertexAttributeType Type;
public readonly int Components;
public readonly int Offset;
public ShaderVertexAttribute(string name, ShaderVertexAttributeType type, int components, int offset)
{
Name = name;
Type = type;
Components = components;
Offset = offset;
}
}
public readonly record struct ShaderVertexAttribute(string Name, ShaderVertexAttributeType Type, int Components, int Offset);
public abstract class ShaderBindings : IShaderBindings
{

View File

@@ -23,25 +23,7 @@ namespace OpenRA
}
public enum MouseInputEvent { Down, Move, Up, Scroll }
public struct MouseInput
{
public MouseInputEvent Event;
public MouseButton Button;
public int2 Location;
public int2 Delta;
public Modifiers Modifiers;
public int MultiTapCount;
public MouseInput(MouseInputEvent ev, MouseButton button, int2 location, int2 delta, Modifiers mods, int multiTapCount)
{
Event = ev;
Button = button;
Location = location;
Delta = delta;
Modifiers = mods;
MultiTapCount = multiTapCount;
}
}
public record struct MouseInput(MouseInputEvent Event, MouseButton Button, int2 Location, int2 Delta, Modifiers Modifiers, int MultiTapCount);
[Flags]
public enum MouseButton

View File

@@ -216,10 +216,8 @@ namespace OpenRA
}
}
public class LocationInit : ValueActorInit<CPos>, ISingleInstanceInit
public class LocationInit(CPos value) : ValueActorInit<CPos>(value), ISingleInstanceInit
{
public LocationInit(CPos value)
: base(value) { }
}
public class OwnerInit : ActorInit, ISingleInstanceInit

View File

@@ -11,16 +11,10 @@
namespace OpenRA
{
public readonly struct TerrainTile
public readonly struct TerrainTile(ushort type, byte index)
{
public readonly ushort Type;
public readonly byte Index;
public TerrainTile(ushort type, byte index)
{
Type = type;
Index = index;
}
public readonly ushort Type = type;
public readonly byte Index = index;
public override int GetHashCode() { return Type.GetHashCode() ^ Index.GetHashCode(); }
@@ -42,16 +36,10 @@ namespace OpenRA
}
}
public readonly struct ResourceTile
public readonly struct ResourceTile(byte type, byte index)
{
public readonly byte Type;
public readonly byte Index;
public ResourceTile(byte type, byte index)
{
Type = type;
Index = index;
}
public readonly byte Type = type;
public readonly byte Index = index;
public override int GetHashCode() { return Type.GetHashCode() ^ Index.GetHashCode(); }
}

View File

@@ -59,16 +59,10 @@ namespace OpenRA
public sealed class MiniYamlNode
{
public readonly struct SourceLocation
public readonly struct SourceLocation(string name, int line)
{
public readonly string Name;
public readonly int Line;
public SourceLocation(string name, int line)
{
Name = name;
Line = line;
}
public readonly string Name = name;
public readonly int Line = line;
public override string ToString() { return $"{Name}:{Line}"; }
}

View File

@@ -54,19 +54,5 @@ namespace OpenRA
}
}
public class PlayerBadge
{
public readonly string Label;
public readonly string Icon;
public readonly string Icon2x;
public readonly string Icon3x;
public PlayerBadge(string label, string icon, string icon2x, string icon3x)
{
Label = label;
Icon = icon;
Icon2x = icon2x;
Icon3x = icon3x;
}
}
public record PlayerBadge(string Label, string Icon, string Icon2x, string Icon3x);
}

View File

@@ -33,10 +33,9 @@ namespace OpenRA.Scripting
// For traitinfos that provide actor / player commands
[AttributeUsage(AttributeTargets.Class)]
public sealed class ScriptPropertyGroupAttribute : Attribute
public sealed class ScriptPropertyGroupAttribute(string category) : Attribute
{
public readonly string Category;
public ScriptPropertyGroupAttribute(string category) { Category = category; }
public readonly string Category = category;
}
// For property groups that are safe to initialize invoke on destroyed actors
@@ -46,28 +45,16 @@ namespace OpenRA.Scripting
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
public sealed class ScriptActorPropertyActivityAttribute : Attribute { }
public abstract class ScriptActorProperties
public abstract class ScriptActorProperties(ScriptContext context, Actor self)
{
protected readonly Actor Self;
protected readonly ScriptContext Context;
protected ScriptActorProperties(ScriptContext context, Actor self)
{
Self = self;
Context = context;
}
protected readonly Actor Self = self;
protected readonly ScriptContext Context = context;
}
public abstract class ScriptPlayerProperties
public abstract class ScriptPlayerProperties(ScriptContext context, Player player)
{
protected readonly Player Player;
protected readonly ScriptContext Context;
protected ScriptPlayerProperties(ScriptContext context, Player player)
{
Player = player;
Context = context;
}
protected readonly Player Player = player;
protected readonly ScriptContext Context = context;
}
/// <summary>
@@ -124,10 +111,9 @@ namespace OpenRA.Scripting
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class ScriptGlobalAttribute : Attribute
public sealed class ScriptGlobalAttribute(string name) : Attribute
{
public readonly string Name;
public ScriptGlobalAttribute(string name) { Name = name; }
public readonly string Name = name;
}
public sealed class ScriptContext : IDisposable

View File

@@ -32,17 +32,7 @@ namespace OpenRA
void SetSoundPosition(ISound sound, WPos position);
}
public class SoundDevice
{
public readonly string Device;
public readonly string Label;
public SoundDevice(string device, string label)
{
Device = device;
Label = label;
}
}
public record SoundDevice(string Device, string Label);
public interface ISoundSource : IDisposable { }

View File

@@ -30,17 +30,7 @@ namespace OpenRA.Support
samples.GetOrAdd(item.Key).Add(new BenchmarkPoint(localTick, item.Value.LastValue));
}
sealed class BenchmarkPoint
{
public int Tick { get; }
public double Value { get; }
public BenchmarkPoint(int tick, double value)
{
Tick = tick;
Value = value;
}
}
readonly record struct BenchmarkPoint(int Tick, double Value);
public void Write()
{

View File

@@ -26,17 +26,7 @@ namespace OpenRA
public TextWriter Writer;
}
readonly struct ChannelData
{
public readonly string Channel;
public readonly string Text;
public ChannelData(string channel, string text)
{
Text = text;
Channel = channel;
}
}
readonly record struct ChannelData(string Channel, string Text);
public static class Log
{

View File

@@ -46,33 +46,21 @@ namespace OpenRA.Traits
public sealed class WeaponReferenceAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public sealed class SequenceReferenceAttribute : Attribute
public sealed class SequenceReferenceAttribute(
string imageReference = null, bool prefix = false, bool allowNullImage = false,
LintDictionaryReference dictionaryReference = LintDictionaryReference.None) : Attribute
{
// The field name in the same trait info that contains the image name.
public readonly string ImageReference;
public readonly bool Prefix;
public readonly bool AllowNullImage;
public readonly LintDictionaryReference DictionaryReference;
public SequenceReferenceAttribute(string imageReference = null, bool prefix = false, bool allowNullImage = false,
LintDictionaryReference dictionaryReference = LintDictionaryReference.None)
{
ImageReference = imageReference;
Prefix = prefix;
AllowNullImage = allowNullImage;
DictionaryReference = dictionaryReference;
}
public readonly string ImageReference = imageReference;
public readonly bool Prefix = prefix;
public readonly bool AllowNullImage = allowNullImage;
public readonly LintDictionaryReference DictionaryReference = dictionaryReference;
}
[AttributeUsage(AttributeTargets.Field)]
public sealed class CursorReferenceAttribute : Attribute
public sealed class CursorReferenceAttribute(LintDictionaryReference dictionaryReference = LintDictionaryReference.None) : Attribute
{
public readonly LintDictionaryReference DictionaryReference;
public CursorReferenceAttribute(LintDictionaryReference dictionaryReference = LintDictionaryReference.None)
{
DictionaryReference = dictionaryReference;
}
public readonly LintDictionaryReference DictionaryReference = dictionaryReference;
}
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
@@ -82,13 +70,9 @@ namespace OpenRA.Traits
public sealed class ConsumedConditionReferenceAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public sealed class PaletteDefinitionAttribute : Attribute
public sealed class PaletteDefinitionAttribute(bool isPlayerPalette = false) : Attribute
{
public readonly bool IsPlayerPalette;
public PaletteDefinitionAttribute(bool isPlayerPalette = false)
{
IsPlayerPalette = isPlayerPalette;
}
public readonly bool IsPlayerPalette = isPlayerPalette;
}
[AttributeUsage(AttributeTargets.Field)]
@@ -108,12 +92,8 @@ namespace OpenRA.Traits
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class TraitLocationAttribute : Attribute
public sealed class TraitLocationAttribute(SystemActors systemActors) : Attribute
{
public readonly SystemActors SystemActors;
public TraitLocationAttribute(SystemActors systemActors)
{
SystemActors = systemActors;
}
public readonly SystemActors SystemActors = systemActors;
}
}

View File

@@ -76,17 +76,7 @@ namespace OpenRA.Traits
public int RevealedCells { get; private set; }
enum ShroudCellType : byte { Shroud, Fog, Visible }
sealed class ShroudSource
{
public readonly SourceType Type;
public readonly PPos[] ProjectedCells;
public ShroudSource(SourceType type, PPos[] projectedCells)
{
Type = type;
ProjectedCells = projectedCells;
}
}
readonly record struct ShroudSource(SourceType Type, PPos[] ProjectedCells);
// Visible is not a super set of Explored. IsExplored may return false even if IsVisible returns true.
[Flags]

View File

@@ -628,16 +628,7 @@ namespace OpenRA.Traits
public interface IObservesVariablesInfo : ITraitInfoInterface { }
public delegate void VariableObserverNotifier(Actor self, IReadOnlyDictionary<string, int> variables);
public struct VariableObserver
{
public VariableObserverNotifier Notifier;
public IEnumerable<string> Variables;
public VariableObserver(VariableObserverNotifier notifier, IEnumerable<string> variables)
{
Notifier = notifier;
Variables = variables;
}
}
public readonly record struct VariableObserver(VariableObserverNotifier Notifier, IEnumerable<string> Variables);
public interface IObservesVariables
{

View File

@@ -18,12 +18,10 @@ using OpenRA.Primitives;
namespace OpenRA.Traits
{
public readonly struct ActorBoundsPair
public readonly struct ActorBoundsPair(Actor actor, Polygon bounds)
{
public readonly Actor Actor;
public readonly Polygon Bounds;
public ActorBoundsPair(Actor actor, Polygon bounds) { Actor = actor; Bounds = bounds; }
public readonly Actor Actor = actor;
public readonly Polygon Bounds = bounds;
public override int GetHashCode() { return Actor.GetHashCode() ^ Bounds.GetHashCode(); }

View File

@@ -182,22 +182,14 @@ namespace OpenRA.Widgets
protected virtual void Dispose(bool disposing) { }
}
public struct WidgetBounds
public struct WidgetBounds(int x, int y, int width, int height)
{
public int X, Y, Width, Height;
public int X = x, Y = y, Width = width, Height = height;
public readonly int Left => X;
public readonly int Right => X + Width;
public readonly int Top => Y;
public readonly int Bottom => Y + Height;
public WidgetBounds(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
public readonly Rectangle ToRectangle()
{
return new Rectangle(X, Y, Width, Height);

View File

@@ -635,12 +635,10 @@ namespace OpenRA
}
}
public readonly struct TraitPair<T> : IEquatable<TraitPair<T>>
public readonly struct TraitPair<T>(Actor actor, T trait) : IEquatable<TraitPair<T>>
{
public readonly Actor Actor;
public readonly T Trait;
public TraitPair(Actor actor, T trait) { Actor = actor; Trait = trait; }
public readonly Actor Actor = actor;
public readonly T Trait = trait;
public static bool operator ==(TraitPair<T> me, TraitPair<T> other) { return me.Actor == other.Actor && Equals(me.Trait, other.Trait); }
public static bool operator !=(TraitPair<T> me, TraitPair<T> other) { return !(me == other); }

View File

@@ -16,16 +16,7 @@ using System.IO;
namespace OpenRA.Mods.Cnc.FileFormats
{
public enum NormalType : byte { TiberianSun = 2, RedAlert2 = 4 }
public readonly struct VxlElement
{
public readonly byte Color;
public readonly byte Normal;
public VxlElement(byte color, byte normal)
{
Color = color;
Normal = normal;
}
}
public readonly record struct VxlElement(byte Color, byte Normal);
public class VxlLimb
{

View File

@@ -182,19 +182,11 @@ namespace OpenRA.Mods.Cnc.Traits
void ITransformActorInitModifier.ModifyTransformActorInit(Actor self, TypeDictionary init) { ModifyActorInit(init); }
}
public class ChronoshiftReturnInit : CompositeActorInit, ISingleInstanceInit
public class ChronoshiftReturnInit(int ticks, int duration, CPos origin, Actor chronosphere) : CompositeActorInit, ISingleInstanceInit
{
public readonly int Ticks;
public readonly int Duration;
public readonly CPos Origin;
public readonly ActorInitActorReference Chronosphere;
public ChronoshiftReturnInit(int ticks, int duration, CPos origin, Actor chronosphere)
{
Ticks = ticks;
Duration = duration;
Origin = origin;
Chronosphere = chronosphere;
}
public readonly int Ticks = ticks;
public readonly int Duration = duration;
public readonly CPos Origin = origin;
public readonly ActorInitActorReference Chronosphere = chronosphere;
}
}

View File

@@ -17,38 +17,26 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common
{
public class FacingInit : ValueActorInit<WAngle>, ISingleInstanceInit
public class FacingInit(WAngle value) : ValueActorInit<WAngle>(value), ISingleInstanceInit
{
public FacingInit(WAngle value)
: base(value) { }
}
public class TerrainOrientationInit : ValueActorInit<WRot>, ISingleInstanceInit, ISuppressInitExport
public class TerrainOrientationInit(WRot value) : ValueActorInit<WRot>(value), ISingleInstanceInit, ISuppressInitExport
{
public TerrainOrientationInit(WRot value)
: base(value) { }
}
public class CreationActivityDelayInit : ValueActorInit<int>, ISingleInstanceInit
public class CreationActivityDelayInit(int value) : ValueActorInit<int>(value), ISingleInstanceInit
{
public CreationActivityDelayInit(int value)
: base(value) { }
}
public class DynamicFacingInit : ValueActorInit<Func<WAngle>>, ISingleInstanceInit
public class DynamicFacingInit(Func<WAngle> value) : ValueActorInit<Func<WAngle>>(value), ISingleInstanceInit
{
public DynamicFacingInit(Func<WAngle> value)
: base(value) { }
}
// Cannot use ValueInit because map.yaml is expected to use the numeric value instead of enum name
public class SubCellInit : ActorInit, ISingleInstanceInit
public class SubCellInit(SubCell value) : ActorInit, ISingleInstanceInit
{
readonly int value;
public SubCellInit(SubCell value)
{
this.value = (int)value;
}
readonly int value = (int)value;
public virtual SubCell Value => (SubCell)value;
@@ -70,23 +58,17 @@ namespace OpenRA.Mods.Common
}
}
public class CenterPositionInit : ValueActorInit<WPos>, ISingleInstanceInit
public class CenterPositionInit(WPos value) : ValueActorInit<WPos>(value), ISingleInstanceInit
{
public CenterPositionInit(WPos value)
: base(value) { }
}
// Allows maps / transformations to specify the faction variant of an actor.
public class FactionInit : ValueActorInit<string>, ISingleInstanceInit
public class FactionInit(string value) : ValueActorInit<string>(value), ISingleInstanceInit
{
public FactionInit(string value)
: base(value) { }
}
public class EffectiveOwnerInit : ValueActorInit<Player>
public class EffectiveOwnerInit(Player value) : ValueActorInit<Player>(value)
{
public EffectiveOwnerInit(Player value)
: base(value) { }
}
sealed class ActorInitLoader : TypeConverter

View File

@@ -16,35 +16,9 @@ using OpenRA.Mods.Common.Traits;
namespace OpenRA.Mods.Common.EditorBrushes
{
public readonly struct BlitTile
{
public readonly TerrainTile TerrainTile;
public readonly ResourceTile ResourceTile;
public readonly ResourceLayerContents? ResourceLayerContents;
public readonly byte Height;
public readonly record struct BlitTile(TerrainTile TerrainTile, ResourceTile ResourceTile, ResourceLayerContents? ResourceLayerContents, byte Height);
public BlitTile(TerrainTile terrainTile, ResourceTile resourceTile, ResourceLayerContents? resourceLayerContents, byte height)
{
TerrainTile = terrainTile;
ResourceTile = resourceTile;
ResourceLayerContents = resourceLayerContents;
Height = height;
}
}
public readonly struct EditorBlitSource
{
public readonly CellRegion CellRegion;
public readonly Dictionary<string, EditorActorPreview> Actors;
public readonly Dictionary<CPos, BlitTile> Tiles;
public EditorBlitSource(CellRegion cellRegion, Dictionary<string, EditorActorPreview> actors, Dictionary<CPos, BlitTile> tiles)
{
CellRegion = cellRegion;
Actors = actors;
Tiles = tiles;
}
}
public readonly record struct EditorBlitSource(CellRegion CellRegion, Dictionary<string, EditorActorPreview> Actors, Dictionary<CPos, BlitTile> Tiles);
[Flags]
public enum MapBlitFilters

View File

@@ -109,19 +109,7 @@ namespace OpenRA.Mods.Common.Widgets
public void Dispose() { }
}
readonly struct CellResource
{
public readonly CPos Cell;
public readonly ResourceLayerContents OldResourceTile;
public readonly string NewResourceType;
public CellResource(CPos cell, ResourceLayerContents oldResourceTile, string newResourceType)
{
Cell = cell;
OldResourceTile = oldResourceTile;
NewResourceType = newResourceType;
}
}
readonly record struct CellResource(CPos Cell, ResourceLayerContents OldResourceTile, string NewResourceType);
sealed class AddResourcesEditorAction : IEditorAction
{

View File

@@ -380,17 +380,5 @@ namespace OpenRA.Mods.Common.Widgets
}
}
sealed class UndoTile
{
public CPos Cell { get; }
public TerrainTile MapTile { get; }
public byte Height { get; }
public UndoTile(CPos cell, TerrainTile mapTile, byte height)
{
Cell = cell;
MapTile = mapTile;
Height = height;
}
}
sealed record UndoTile(CPos Cell, TerrainTile MapTile, byte Height);
}

View File

@@ -178,68 +178,36 @@ namespace OpenRA.Mods.Common.FileFormats
}
}
readonly struct CommonHeader
readonly struct CommonHeader(Stream stream)
{
public const long Size = 16;
public readonly uint Version;
public readonly uint VolumeInfo;
public readonly long CabDescriptorOffset;
public readonly uint CabDescriptorSize;
public CommonHeader(Stream stream)
{
Version = stream.ReadUInt32();
VolumeInfo = stream.ReadUInt32();
CabDescriptorOffset = stream.ReadUInt32();
CabDescriptorSize = stream.ReadUInt32();
}
public readonly uint Version = stream.ReadUInt32();
public readonly uint VolumeInfo = stream.ReadUInt32();
public readonly long CabDescriptorOffset = stream.ReadUInt32();
public readonly uint CabDescriptorSize = stream.ReadUInt32();
}
readonly struct VolumeHeader
readonly struct VolumeHeader(Stream stream)
{
public readonly uint DataOffset;
public readonly uint DataOffsetHigh;
public readonly uint FirstFileIndex;
public readonly uint LastFileIndex;
public readonly uint DataOffset = stream.ReadUInt32();
public readonly uint DataOffsetHigh = stream.ReadUInt32();
public readonly uint FirstFileIndex = stream.ReadUInt32();
public readonly uint LastFileIndex = stream.ReadUInt32();
public readonly uint FirstFileOffset;
public readonly uint FirstFileOffsetHigh;
public readonly uint FirstFileSizeExpanded;
public readonly uint FirstFileSizeExpandedHigh;
public readonly uint FirstFileOffset = stream.ReadUInt32();
public readonly uint FirstFileOffsetHigh = stream.ReadUInt32();
public readonly uint FirstFileSizeExpanded = stream.ReadUInt32();
public readonly uint FirstFileSizeExpandedHigh = stream.ReadUInt32();
public readonly uint FirstFileSizeCompressed;
public readonly uint FirstFileSizeCompressedHigh;
public readonly uint LastFileOffset;
public readonly uint LastFileOffsetHigh;
public readonly uint FirstFileSizeCompressed = stream.ReadUInt32();
public readonly uint FirstFileSizeCompressedHigh = stream.ReadUInt32();
public readonly uint LastFileOffset = stream.ReadUInt32();
public readonly uint LastFileOffsetHigh = stream.ReadUInt32();
public readonly uint LastFileSizeExpanded;
public readonly uint LastFileSizeExpandedHigh;
public readonly uint LastFileSizeCompressed;
public readonly uint LastFileSizeCompressedHigh;
public VolumeHeader(Stream stream)
{
DataOffset = stream.ReadUInt32();
DataOffsetHigh = stream.ReadUInt32();
FirstFileIndex = stream.ReadUInt32();
LastFileIndex = stream.ReadUInt32();
FirstFileOffset = stream.ReadUInt32();
FirstFileOffsetHigh = stream.ReadUInt32();
FirstFileSizeExpanded = stream.ReadUInt32();
FirstFileSizeExpandedHigh = stream.ReadUInt32();
FirstFileSizeCompressed = stream.ReadUInt32();
FirstFileSizeCompressedHigh = stream.ReadUInt32();
LastFileOffset = stream.ReadUInt32();
LastFileOffsetHigh = stream.ReadUInt32();
LastFileSizeExpanded = stream.ReadUInt32();
LastFileSizeExpandedHigh = stream.ReadUInt32();
LastFileSizeCompressed = stream.ReadUInt32();
LastFileSizeCompressedHigh = stream.ReadUInt32();
}
public readonly uint LastFileSizeExpanded = stream.ReadUInt32();
public readonly uint LastFileSizeExpandedHigh = stream.ReadUInt32();
public readonly uint LastFileSizeCompressed = stream.ReadUInt32();
public readonly uint LastFileSizeCompressedHigh = stream.ReadUInt32();
}
sealed class CabExtracter

View File

@@ -22,17 +22,7 @@ namespace OpenRA.Mods.Common.FileSystem
{
public sealed class InstallShieldPackage : IReadOnlyPackage
{
public readonly struct Entry
{
public readonly uint Offset;
public readonly uint Length;
public Entry(uint offset, uint length)
{
Offset = offset;
Length = length;
}
}
public readonly record struct Entry(uint Offset, uint Length);
public string Name { get; }
public IEnumerable<string> Contents => index.Keys;

View File

@@ -74,17 +74,7 @@ namespace OpenRA.Mods.Common.Graphics
}
}
public struct SpriteSequenceField<T>
{
public string Key;
public T DefaultValue;
public SpriteSequenceField(string key, T defaultValue)
{
Key = key;
DefaultValue = defaultValue;
}
}
public readonly record struct SpriteSequenceField<T>(string Key, T DefaultValue);
[Desc("Generic sprite sequence implementation, mostly unencumbered with game- or artwork-specific logic.")]
public class DefaultSpriteSequence : ISpriteSequence

View File

@@ -18,13 +18,9 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Lint
{
[AttributeUsage(AttributeTargets.Class)]
public sealed class ChromeLogicArgsHotkeys : Attribute
public sealed class ChromeLogicArgsHotkeys(params string[] logicArgKeys) : Attribute
{
public string[] LogicArgKeys;
public ChromeLogicArgsHotkeys(params string[] logicArgKeys)
{
LogicArgKeys = logicArgKeys;
}
public string[] LogicArgKeys = logicArgKeys;
}
[AttributeUsage(AttributeTargets.Method)]

View File

@@ -190,24 +190,15 @@ namespace OpenRA.Mods.Common.Orders
return order;
}
protected sealed class UnitOrderResult
protected sealed class UnitOrderResult(Actor actor, IOrderTargeter order, IIssueOrder trait, string cursor, in Target target)
{
public readonly Actor Actor;
public readonly IOrderTargeter Order;
public readonly IIssueOrder Trait;
public readonly string Cursor;
public readonly Actor Actor = actor;
public readonly IOrderTargeter Order = order;
public readonly IIssueOrder Trait = trait;
public readonly string Cursor = cursor;
public ref readonly Target Target => ref target;
readonly Target target;
public UnitOrderResult(Actor actor, IOrderTargeter order, IIssueOrder trait, string cursor, in Target target)
{
Actor = actor;
Order = order;
Trait = trait;
Cursor = cursor;
this.target = target;
}
readonly Target target = target;
}
public virtual bool ClearSelectionOnLeftClick => true;

View File

@@ -18,15 +18,9 @@ namespace OpenRA.Mods.Common.Scripting
/// Used to override the Emmy Lua type generated by the <see cref="ExtractEmmyLuaAPI"/> utility command.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
public sealed class ScriptEmmyTypeOverrideAttribute : Attribute
public sealed class ScriptEmmyTypeOverrideAttribute(string typeDeclaration, string genericTypeDeclaration = null) : Attribute
{
public readonly string TypeDeclaration;
public readonly string GenericTypeDeclaration;
public ScriptEmmyTypeOverrideAttribute(string typeDeclaration, string genericTypeDeclaration = null)
{
TypeDeclaration = typeDeclaration;
GenericTypeDeclaration = genericTypeDeclaration;
}
public readonly string TypeDeclaration = typeDeclaration;
public readonly string GenericTypeDeclaration = genericTypeDeclaration;
}
}

View File

@@ -19,19 +19,7 @@ using OpenRA.Support;
namespace OpenRA.Mods.Common.Terrain
{
public class TheaterTemplate
{
public readonly Sprite[] Sprites;
public readonly int Stride;
public readonly int Variants;
public TheaterTemplate(Sprite[] sprites, int stride, int variants)
{
Sprites = sprites;
Stride = stride;
Variants = variants;
}
}
public record TheaterTemplate(Sprite[] Sprites, int Stride, int Variants);
public sealed class DefaultTileCache : IDisposable
{

View File

@@ -40,18 +40,11 @@ namespace OpenRA.Mods.Common.Traits
public class ExternalCondition : ITick, INotifyCreated, INotifyOwnerChanged
{
readonly struct TimedToken
readonly struct TimedToken(int token, Actor self, object source, int duration)
{
public readonly int Expires;
public readonly int Token;
public readonly object Source;
public TimedToken(int token, Actor self, object source, int duration)
{
Token = token;
Expires = self.World.WorldTick + duration;
Source = source;
}
public readonly int Expires = self.World.WorldTick + duration;
public readonly int Token = token;
public readonly object Source = source;
}
public readonly ExternalConditionInfo Info;

View File

@@ -30,20 +30,12 @@ namespace OpenRA.Mods.Common.Traits
public class Demolishable : ConditionalTrait<DemolishableInfo>, IDemolishable, ITick, INotifyOwnerChanged
{
sealed class DemolishAction
sealed class DemolishAction(Actor saboteur, int delay, int token, BitSet<DamageType> damageTypes)
{
public readonly Actor Saboteur;
public readonly int Token;
public int Delay;
public readonly BitSet<DamageType> DamageTypes;
public DemolishAction(Actor saboteur, int delay, int token, BitSet<DamageType> damageTypes)
{
Saboteur = saboteur;
Delay = delay;
Token = token;
DamageTypes = damageTypes;
}
public readonly Actor Saboteur = saboteur;
public readonly int Token = token;
public int Delay = delay;
public readonly BitSet<DamageType> DamageTypes = damageTypes;
}
readonly List<DemolishAction> actions = [];

View File

@@ -23,15 +23,9 @@ namespace OpenRA.Mods.Common.Traits
public sealed class LocomotorReferenceAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public sealed class NotificationReferenceAttribute : Attribute
public sealed class NotificationReferenceAttribute(string type = null, string typeFromField = null) : Attribute
{
public readonly string NotificationTypeFieldName = null;
public readonly string NotificationType = null;
public NotificationReferenceAttribute(string type = null, string typeFromField = null)
{
NotificationType = type;
NotificationTypeFieldName = typeFromField;
}
public readonly string NotificationTypeFieldName = typeFromField;
public readonly string NotificationType = type;
}
}

View File

@@ -40,14 +40,10 @@ namespace OpenRA.Mods.Common.Traits
bool isRendering;
bool created;
sealed class FrozenState
sealed class FrozenState(FrozenActor frozenActor)
{
public readonly FrozenActor FrozenActor;
public readonly FrozenActor FrozenActor = frozenActor;
public bool IsVisible;
public FrozenState(FrozenActor frozenActor)
{
FrozenActor = frozenActor;
}
}
public FrozenUnderFog(ActorInitializer init, FrozenUnderFogInfo info)

View File

@@ -170,18 +170,6 @@ namespace OpenRA.Mods.Common.Traits
return points;
}
sealed class Arrow
{
public Sprite Sprite { get; }
public double EndAngle { get; }
public WAngle Direction { get; }
public Arrow(Sprite sprite, double endAngle, WAngle direction)
{
Sprite = sprite;
EndAngle = endAngle;
Direction = direction;
}
}
sealed record Arrow(Sprite Sprite, double EndAngle, WAngle Direction);
}
}

View File

@@ -130,19 +130,7 @@ namespace OpenRA.Mods.Common.Traits
public class Locomotor : IWorldLoaded
{
readonly struct CellCache
{
public readonly LongBitSet<PlayerBitMask> Immovable;
public readonly LongBitSet<PlayerBitMask> Crushable;
public readonly CellFlag CellFlag;
public CellCache(LongBitSet<PlayerBitMask> immovable, CellFlag cellFlag, LongBitSet<PlayerBitMask> crushable)
{
Immovable = immovable;
Crushable = crushable;
CellFlag = cellFlag;
}
}
readonly record struct CellCache(LongBitSet<PlayerBitMask> Immovable, CellFlag CellFlag, LongBitSet<PlayerBitMask> Crushable);
public readonly LocomotorInfo Info;

View File

@@ -378,17 +378,7 @@ namespace OpenRA.Mods.Common.Traits
disposed = true;
}
readonly struct MapLine
{
public readonly float2 Start;
public readonly float2 End;
public MapLine(float2 start, float2 end)
{
Start = start;
End = end;
}
}
readonly record struct MapLine(float2 Start, float2 End);
IEnumerable<IRenderable> IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr)
{

View File

@@ -17,17 +17,11 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
public readonly struct ResourceLayerContents
public readonly struct ResourceLayerContents(string type, int density)
{
public static readonly ResourceLayerContents Empty = default;
public readonly string Type;
public readonly int Density;
public ResourceLayerContents(string type, int density)
{
Type = type;
Density = density;
}
public readonly string Type = type;
public readonly int Density = density;
}
[TraitLocation(SystemActors.World)]

View File

@@ -94,16 +94,10 @@ namespace OpenRA.Mods.Common.Traits
BottomLeft
}
readonly struct TileInfo
readonly struct TileInfo(in float3 screenPosition, byte variant)
{
public readonly float3 ScreenPosition;
public readonly byte Variant;
public TileInfo(in float3 screenPosition, byte variant)
{
ScreenPosition = screenPosition;
Variant = variant;
}
public readonly float3 ScreenPosition = screenPosition;
public readonly byte Variant = variant;
}
readonly ShroudRendererInfo info;

View File

@@ -35,22 +35,13 @@ namespace OpenRA.Mods.Common.Traits
public sealed class TerrainLighting : ITerrainLighting
{
sealed class LightSource
sealed class LightSource(WPos pos, CPos cell, WDist range, float intensity, in float3 tint)
{
public readonly WPos Pos;
public readonly CPos Cell;
public readonly WDist Range;
public readonly float Intensity;
public readonly float3 Tint;
public LightSource(WPos pos, CPos cell, WDist range, float intensity, in float3 tint)
{
Pos = pos;
Cell = cell;
Range = range;
Intensity = intensity;
Tint = tint;
}
public readonly WPos Pos = pos;
public readonly CPos Cell = cell;
public readonly WDist Range = range;
public readonly float Intensity = intensity;
public readonly float3 Tint = tint;
}
readonly TerrainLightingInfo info;

View File

@@ -28,22 +28,14 @@ namespace OpenRA.Mods.Common.Traits
public class WarheadDebugOverlay : IRenderAnnotations
{
sealed class WHImpact
sealed class WHImpact(WPos pos, WDist[] range, int time, Color color)
{
public readonly WPos CenterPosition;
public readonly WDist[] Range;
public readonly Color Color;
public int Time;
public readonly WPos CenterPosition = pos;
public readonly WDist[] Range = range;
public readonly Color Color = color;
public int Time = time;
public WDist OuterRange => Range[^1];
public WHImpact(WPos pos, WDist[] range, int time, Color color)
{
CenterPosition = pos;
Range = range;
Color = color;
Time = time;
}
}
readonly WarheadDebugOverlayInfo info;

View File

@@ -200,22 +200,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
struct ExtractionCandidate
struct ExtractionCandidate(string key, string type, string value, MiniYamlNodeBuilder node)
{
public string Chrome;
public readonly string Key;
public readonly string Type;
public readonly string Value;
public readonly List<MiniYamlNodeBuilder> Nodes;
public ExtractionCandidate(string key, string type, string value, MiniYamlNodeBuilder node)
{
Chrome = null;
Key = key;
Type = type;
Value = value;
Nodes = [node];
}
public string Chrome = null;
public readonly string Key = key;
public readonly string Type = type;
public readonly string Value = value;
public readonly List<MiniYamlNodeBuilder> Nodes = [node];
}
static string ClearContainersAndToLower(string node)

View File

@@ -229,22 +229,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
struct ExtractionCandidate
struct ExtractionCandidate(string actor, string key, string value, MiniYamlNodeBuilder node)
{
public string Filename;
public readonly string Actor;
public readonly string Key;
public readonly string Value;
public readonly List<MiniYamlNodeBuilder> Nodes;
public ExtractionCandidate(string actor, string key, string value, MiniYamlNodeBuilder node)
{
Filename = null;
Actor = actor;
Key = key;
Value = value;
Nodes = [node];
}
public string Filename = null;
public readonly string Actor = actor;
public readonly string Key = key;
public readonly string Value = value;
public readonly List<MiniYamlNodeBuilder> Nodes = [node];
}
static string ToLowerActor(string actor)

View File

@@ -230,17 +230,5 @@ namespace OpenRA.Mods.Common.Widgets
}
}
public class LineGraphSeries
{
public string Key;
public Color Color;
public IEnumerable<float> Points;
public LineGraphSeries(string key, Color color, IEnumerable<float> points)
{
Key = key;
Color = color;
Points = points;
}
}
public record LineGraphSeries(string Key, Color Color, IEnumerable<float> Points);
}

View File

@@ -24,21 +24,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[FluentReference("actorType")]
const string ActorTypeTooltip = "label-actor-type";
sealed class ActorSelectorActor
{
public readonly ActorInfo Actor;
public readonly string[] Categories;
public readonly string[] SearchTerms;
public readonly string Tooltip;
public ActorSelectorActor(ActorInfo actor, string[] categories, string[] searchTerms, string tooltip)
{
Actor = actor;
Categories = categories;
SearchTerms = searchTerms;
Tooltip = tooltip;
}
}
sealed record ActorSelectorActor(ActorInfo Actor, string[] Categories, string[] SearchTerms, string Tooltip);
readonly DropDownButtonWidget ownersDropDown;
readonly Ruleset mapRules;

View File

@@ -30,19 +30,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public string UiLabel;
}
sealed class SaveDirectory
{
public readonly Folder Folder;
public readonly string DisplayName;
public readonly MapClassification Classification;
public SaveDirectory(Folder folder, string displayName, MapClassification classification)
{
Folder = folder;
DisplayName = displayName;
Classification = classification;
}
}
sealed record SaveDirectory(Folder Folder, string DisplayName, MapClassification Classification);
[FluentReference]
const string SaveMapFailedTitle = "dialog-save-map-failed.title";

View File

@@ -42,19 +42,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[FluentReference]
const string Slot = "options-lobby-slot.slot";
sealed class SlotDropDownOption
{
public readonly string Title;
public readonly string Order;
public readonly Func<bool> Selected;
public SlotDropDownOption(string title, string order, Func<bool> selected)
{
Title = title;
Order = order;
Selected = selected;
}
}
sealed record SlotDropDownOption(string Title, string Order, Func<bool> Selected);
public static void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot,
Session.Client client, OrderManager orderManager, MapPreview map, ModData modData)
@@ -716,17 +704,4 @@ namespace OpenRA.Mods.Common.Widgets.Logic
widget.IsVisible = () => false;
}
}
sealed class ShowPlayerActionDropDownOption
{
public Action Click { get; set; }
public string Title;
public Func<bool> Selected = () => false;
public ShowPlayerActionDropDownOption(string title, Action click)
{
Click = click;
Title = title;
}
}
}

View File

@@ -21,17 +21,7 @@ namespace OpenRA.Mods.D2k.PackageLoaders
{
sealed class D2kSoundResources : IReadOnlyPackage
{
readonly struct Entry
{
public readonly uint Offset;
public readonly uint Length;
public Entry(uint offset, uint length)
{
Offset = offset;
Length = length;
}
}
readonly record struct Entry(uint Offset, uint Length);
public string Name { get; }
public IEnumerable<string> Contents => index.Keys;