Use read-only autoimplemented property when possible

This commit is contained in:
Eduardo Cáceres
2022-05-02 13:06:21 +02:00
committed by atlimit8
parent 79f321cb44
commit 7eb64ea6fc
52 changed files with 113 additions and 113 deletions

View File

@@ -65,9 +65,9 @@ namespace OpenRA
public int Generation;
public Actor ReplacedByActor;
public IEffectiveOwner EffectiveOwner { get; private set; }
public IOccupySpace OccupiesSpace { get; private set; }
public ITargetable[] Targetables { get; private set; }
public IEffectiveOwner EffectiveOwner { get; }
public IOccupySpace OccupiesSpace { get; }
public ITargetable[] Targetables { get; }
public bool IsIdle => CurrentActivity == null;
public bool IsDead => Disposed || (health != null && health.IsDead);
@@ -102,7 +102,7 @@ namespace OpenRA
/// <summary>Read-only version of conditionCache that is passed to IConditionConsumers.</summary>
readonly IReadOnlyDictionary<string, int> readOnlyConditionCache;
internal SyncHash[] SyncHashes { get; private set; }
internal SyncHash[] SyncHashes { get; }
readonly IFacing facing;
readonly IHealth health;

View File

@@ -26,11 +26,11 @@ namespace OpenRA.FileFormats
{
static readonly byte[] Signature = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
public int Width { get; private set; }
public int Height { get; private set; }
public Color[] Palette { get; private set; }
public byte[] Data { get; private set; }
public SpriteFrameType Type { get; private set; }
public int Width { get; }
public int Height { get; }
public Color[] Palette { get; }
public byte[] Data { get; }
public SpriteFrameType Type { get; }
public Dictionary<string, string> EmbeddedData = new Dictionary<string, string>();
public int PixelStride => Type == SpriteFrameType.Indexed8 ? 1 : Type == SpriteFrameType.Rgb24 ? 3 : 4;

View File

@@ -142,7 +142,7 @@ namespace OpenRA.FileSystem
sealed class ZipFolder : IReadOnlyPackage
{
public string Name => path;
public ReadOnlyZipFile Parent { get; private set; }
public ReadOnlyZipFile Parent { get; }
readonly string path;
public ZipFolder(ReadOnlyZipFile parent, string path)

View File

@@ -35,7 +35,7 @@ namespace OpenRA
/// <summary>Gets the game's duration, from the time the game started until the replay recording stopped.</summary>
public TimeSpan Duration => EndTimeUtc > StartTimeUtc ? EndTimeUtc - StartTimeUtc : TimeSpan.Zero;
public IList<Player> Players { get; private set; }
public IList<Player> Players { get; }
public HashSet<int> DisabledSpawnPoints = new HashSet<int>();
public MapPreview MapPreview => Game.ModData.MapCache[MapUid];
public IEnumerable<Player> HumanPlayers { get { return Players.Where(p => p.IsHuman); } }

View File

@@ -17,8 +17,8 @@ namespace OpenRA.Graphics
{
public sealed class HardwarePalette : IDisposable
{
public ITexture Texture { get; private set; }
public ITexture ColorShifts { get; private set; }
public ITexture Texture { get; }
public ITexture ColorShifts { get; }
public int Height { get; private set; }
readonly Dictionary<string, ImmutablePalette> palettes = new Dictionary<string, ImmutablePalette>();

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Graphics
{
public sealed class SpriteFont : IDisposable
{
public int TopOffset { get; private set; }
public int TopOffset { get; }
readonly int size;
readonly SheetBuilder builder;
readonly IFont font;

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Graphics
public readonly Size TileSize;
public readonly int TileScale;
public readonly World World;
public Viewport Viewport { get; private set; }
public Viewport Viewport { get; }
public readonly ITerrainLighting TerrainLighting;
public event Action PaletteInvalidated = null;

View File

@@ -121,7 +121,7 @@ namespace OpenRA
new WVec(256, 256, 0), // bottom right - index 5
};
public CellRamp[] Ramps { get; private set; }
public CellRamp[] Ramps { get; }
internal readonly CVec[][] TilesByDistance;

View File

@@ -37,7 +37,7 @@ namespace OpenRA
public readonly IVideoLoader[] VideoLoaders;
public readonly HotkeyManager Hotkeys;
public readonly Translation Translation;
public ILoadScreen LoadScreen { get; private set; }
public ILoadScreen LoadScreen { get; }
public CursorProvider CursorProvider { get; private set; }
public FS ModFiles;
public IReadOnlyFileSystem DefaultFileSystem => ModFiles;
@@ -152,7 +152,7 @@ namespace OpenRA
CursorProvider = new CursorProvider(this);
}
public IEnumerable<string> Languages { get; private set; }
public IEnumerable<string> Languages { get; }
public Map PrepareMap(string uid)
{

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Network
public TickTime LastTickTime;
public bool GameStarted => NetFrameNumber != 0;
public IConnection Connection { get; private set; }
public IConnection Connection { get; }
internal int GameSaveLastFrame = -1;
internal int GameSaveLastSyncFrame = -1;

View File

@@ -77,7 +77,7 @@ namespace OpenRA
// Players in mission maps must not leave the player view
public bool Spectating => !inMissionMap && (spectating || WinState != WinState.Undefined);
public World World { get; private set; }
public World World { get; }
readonly bool inMissionMap;
readonly bool spectating;

View File

@@ -24,24 +24,24 @@ namespace OpenRA
{
enum RenderType { None, World, UI }
public SpriteRenderer WorldSpriteRenderer { get; private set; }
public RgbaSpriteRenderer WorldRgbaSpriteRenderer { get; private set; }
public RgbaColorRenderer WorldRgbaColorRenderer { get; private set; }
public ModelRenderer WorldModelRenderer { get; private set; }
public RgbaColorRenderer RgbaColorRenderer { get; private set; }
public SpriteRenderer SpriteRenderer { get; private set; }
public RgbaSpriteRenderer RgbaSpriteRenderer { get; private set; }
public SpriteRenderer WorldSpriteRenderer { get; }
public RgbaSpriteRenderer WorldRgbaSpriteRenderer { get; }
public RgbaColorRenderer WorldRgbaColorRenderer { get; }
public ModelRenderer WorldModelRenderer { get; }
public RgbaColorRenderer RgbaColorRenderer { get; }
public SpriteRenderer SpriteRenderer { get; }
public RgbaSpriteRenderer RgbaSpriteRenderer { get; }
public bool WindowHasInputFocus => Window.HasInputFocus;
public bool WindowIsSuspended => Window.IsSuspended;
public IReadOnlyDictionary<string, SpriteFont> Fonts;
internal IPlatformWindow Window { get; private set; }
internal IGraphicsContext Context { get; private set; }
internal IPlatformWindow Window { get; }
internal IGraphicsContext Context { get; }
internal int SheetSize { get; private set; }
internal int TempBufferSize { get; private set; }
internal int SheetSize { get; }
internal int TempBufferSize { get; }
readonly IVertexBuffer<Vertex> tempBuffer;
readonly Stack<Rectangle> scissorState = new Stack<Rectangle>();

View File

@@ -129,8 +129,8 @@ namespace OpenRA.Scripting
// Restrict the number of instructions that will be run per map function call
const int MaxUserScriptInstructions = 1000000;
public World World { get; private set; }
public WorldRenderer WorldRenderer { get; private set; }
public World World { get; }
public WorldRenderer WorldRenderer { get; }
readonly MemoryConstrainedLuaRuntime runtime;
readonly LuaFunction tick;

View File

@@ -46,7 +46,7 @@ namespace OpenRA
MusicInfo currentMusic;
Dictionary<uint, ISound> currentSounds = new Dictionary<uint, ISound>();
readonly Dictionary<string, ISound> currentNotifications = new Dictionary<string, ISound>();
public bool DummyEngine { get; private set; }
public bool DummyEngine { get; }
public Sound(IPlatform platform, SoundSettings soundSettings)
{

View File

@@ -31,8 +31,8 @@ namespace OpenRA.Support
class BenchmarkPoint
{
public int Tick { get; private set; }
public double Value { get; private set; }
public int Tick { get; }
public double Value { get; }
public BenchmarkPoint(int tick, double value)
{

View File

@@ -176,7 +176,7 @@ namespace OpenRA
}
}
public bool RulesContainTemporaryBlocker { get; private set; }
public bool RulesContainTemporaryBlocker { get; }
bool wasLoadingGameSave;

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
{
sealed class BigFile : IReadOnlyPackage
{
public string Name { get; private set; }
public string Name { get; }
public IEnumerable<string> Contents => index.Keys;
readonly Dictionary<string, Entry> index = new Dictionary<string, Entry>();

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
{
public sealed class MixFile : IReadOnlyPackage
{
public string Name { get; private set; }
public string Name { get; }
public IEnumerable<string> Contents => index.Keys;
readonly Dictionary<string, PackageEntry> index;

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
sealed class PakFile : IReadOnlyPackage
{
public string Name { get; private set; }
public string Name { get; }
public IEnumerable<string> Contents => index.Keys;
readonly Dictionary<string, Entry> index = new Dictionary<string, Entry>();

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
class ShpD2Frame : ISpriteFrame
{
public SpriteFrameType Type => SpriteFrameType.Indexed8;
public Size Size { get; private set; }
public Size Size { get; }
public Size FrameSize => Size;
public float2 Offset => float2.Zero;
public byte[] Data { get; set; }

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
return int.Parse(match.Groups[group].Value);
}
public IReadOnlyList<ISpriteFrame> Frames { get; private set; }
public IReadOnlyList<ISpriteFrame> Frames { get; }
public ShpRemasteredSprite(Stream stream)
{

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
}
}
public IReadOnlyList<ISpriteFrame> Frames { get; private set; }
public IReadOnlyList<ISpriteFrame> Frames { get; }
public readonly Size Size;
int recurseDepth = 0;

View File

@@ -21,8 +21,8 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
class TmpRAFrame : ISpriteFrame
{
public SpriteFrameType Type => SpriteFrameType.Indexed8;
public Size Size { get; private set; }
public Size FrameSize { get; private set; }
public Size Size { get; }
public Size FrameSize { get; }
public float2 Offset => float2.Zero;
public byte[] Data { get; set; }
public bool DisableExportPadding => false;

View File

@@ -21,8 +21,8 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
class TmpTDFrame : ISpriteFrame
{
public SpriteFrameType Type => SpriteFrameType.Indexed8;
public Size Size { get; private set; }
public Size FrameSize { get; private set; }
public Size Size { get; }
public Size FrameSize { get; }
public float2 Offset => float2.Zero;
public byte[] Data { get; set; }
public bool DisableExportPadding => false;

View File

@@ -38,9 +38,9 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
class TmpTSFrame : ISpriteFrame
{
public SpriteFrameType Type => SpriteFrameType.Indexed8;
public Size Size { get; private set; }
public Size Size { get; }
public Size FrameSize => Size;
public float2 Offset { get; private set; }
public float2 Offset { get; }
public byte[] Data { get; set; }
public byte[] DepthData { get; set; }
public bool DisableExportPadding => false;

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Commands
public class ChatCommands : INotifyChat
{
public Dictionary<string, IChatCommand> Commands { get; private set; }
public Dictionary<string, IChatCommand> Commands { get; }
public ChatCommands()
{

View File

@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Widgets
class CopyPasteEditorAction : IEditorAction
{
public string Text { get; private set; }
public string Text { get; }
readonly MapCopyFilters copyFilters;
readonly Dictionary<CPos, (TerrainTile Tile, ResourceTile Resource, byte Height)> tiles;
@@ -270,10 +270,10 @@ namespace OpenRA.Mods.Common.Widgets
class UndoCopyPaste
{
public CPos Cell { get; private set; }
public TerrainTile MapTile { get; private set; }
public ResourceTile ResourceTile { get; private set; }
public byte Height { get; private set; }
public CPos Cell { get; }
public TerrainTile MapTile { get; }
public ResourceTile ResourceTile { get; }
public byte Height { get; }
public UndoCopyPaste(CPos cell, TerrainTile mapTile, ResourceTile resourceTile, byte height)
{

View File

@@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Widgets
class RemoveActorAction : IEditorAction
{
public string Text { get; private set; }
public string Text { get; }
readonly EditorActorLayer editorActorLayer;
readonly EditorActorPreview actor;
@@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Widgets
class RemoveResourceAction : IEditorAction
{
public string Text { get; private set; }
public string Text { get; }
readonly IResourceLayer resourceLayer;
readonly CPos cell;

View File

@@ -153,7 +153,7 @@ namespace OpenRA.Mods.Common.Widgets
class PaintTileEditorAction : IEditorAction
{
public string Text { get; private set; }
public string Text { get; }
readonly ushort template;
readonly Map map;
@@ -222,7 +222,7 @@ namespace OpenRA.Mods.Common.Widgets
class FloodFillEditorAction : IEditorAction
{
public string Text { get; private set; }
public string Text { get; }
readonly ushort template;
readonly Map map;
@@ -357,9 +357,9 @@ namespace OpenRA.Mods.Common.Widgets
class UndoTile
{
public CPos Cell { get; private set; }
public TerrainTile MapTile { get; private set; }
public byte Height { get; private set; }
public CPos Cell { get; }
public TerrainTile MapTile { get; }
public byte Height { get; }
public UndoTile(CPos cell, TerrainTile mapTile, byte height)
{

View File

@@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.FileFormats
public class IniSection : IEnumerable<KeyValuePair<string, string>>
{
public string Name { get; private set; }
public string Name { get; }
readonly Dictionary<string, string> values = new Dictionary<string, string>();
public IniSection(string name)

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.FileSystem
}
}
public string Name { get; private set; }
public string Name { get; }
public IEnumerable<string> Contents => index.Keys;
readonly Dictionary<string, Entry> index = new Dictionary<string, Entry>();

View File

@@ -132,20 +132,20 @@ namespace OpenRA.Mods.Common.Graphics
protected readonly ISpriteSequenceLoader Loader;
public string Name { get; private set; }
public string Name { get; }
public int Start { get; private set; }
public int Length { get; private set; }
public int Stride { get; private set; }
public int Facings { get; private set; }
public int Tick { get; private set; }
public int ZOffset { get; private set; }
public float ZRamp { get; private set; }
public int ShadowStart { get; private set; }
public int ShadowZOffset { get; private set; }
public int Facings { get; }
public int Tick { get; }
public int ZOffset { get; }
public float ZRamp { get; }
public int ShadowStart { get; }
public int ShadowZOffset { get; }
public int[] Frames { get; private set; }
public Rectangle Bounds { get; private set; }
public bool IgnoreWorldTint { get; private set; }
public float Scale { get; private set; }
public bool IgnoreWorldTint { get; }
public float Scale { get; }
public readonly uint[] EmbeddedPalette;

View File

@@ -26,8 +26,8 @@ namespace OpenRA.Mods.Common.Orders
this.cursor = cursor;
}
public string OrderID { get; private set; }
public int OrderPriority { get; private set; }
public string OrderID { get; }
public int OrderPriority { get; }
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool CanTarget(Actor self, in Target target, ref TargetModifiers modifiers, ref string cursor)

View File

@@ -29,8 +29,8 @@ namespace OpenRA.Mods.Common.Orders
this.targetAllyUnits = targetAllyUnits;
}
public string OrderID { get; private set; }
public int OrderPriority { get; private set; }
public string OrderID { get; }
public int OrderPriority { get; }
public bool? ForceAttack = null;
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }

View File

@@ -47,11 +47,11 @@ namespace OpenRA.Mods.Common.SpriteLoaders
{
class DdsFrame : ISpriteFrame
{
public SpriteFrameType Type { get; private set; }
public Size Size { get; private set; }
public SpriteFrameType Type { get; }
public Size Size { get; }
public Size FrameSize => Size;
public float2 Offset => float2.Zero;
public byte[] Data { get; private set; }
public byte[] Data { get; }
public bool DisableExportPadding => false;
public DdsFrame(Stream stream)
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
}
}
public IReadOnlyList<ISpriteFrame> Frames { get; private set; }
public IReadOnlyList<ISpriteFrame> Frames { get; }
public DdsSprite(Stream stream)
{

View File

@@ -21,9 +21,9 @@ namespace OpenRA.Mods.Common.SpriteLoaders
class ShpTSFrame : ISpriteFrame
{
public SpriteFrameType Type => SpriteFrameType.Indexed8;
public Size Size { get; private set; }
public Size FrameSize { get; private set; }
public float2 Offset { get; private set; }
public Size Size { get; }
public Size FrameSize { get; }
public float2 Offset { get; }
public byte[] Data { get; set; }
public bool DisableExportPadding => false;

View File

@@ -70,11 +70,11 @@ namespace OpenRA.Mods.Common.SpriteLoaders
{
public class TgaFrame : ISpriteFrame
{
public SpriteFrameType Type { get; private set; }
public Size Size { get; private set; }
public Size FrameSize { get; private set; }
public float2 Offset { get; private set; }
public byte[] Data { get; private set; }
public SpriteFrameType Type { get; }
public Size Size { get; }
public Size FrameSize { get; }
public float2 Offset { get; }
public byte[] Data { get; }
public bool DisableExportPadding => false;
public TgaFrame()
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
}
}
public IReadOnlyList<ISpriteFrame> Frames { get; private set; }
public IReadOnlyList<ISpriteFrame> Frames { get; }
public TgaSprite(Stream stream)
{

View File

@@ -426,7 +426,7 @@ namespace OpenRA.Mods.Common.Traits
}
public string OrderID { get; private set; }
public int OrderPriority { get; private set; }
public int OrderPriority { get; }
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
bool CanTargetActor(Actor self, in Target target, ref TargetModifiers modifiers, ref string cursor)

View File

@@ -279,7 +279,7 @@ namespace OpenRA.Mods.Common.Traits
readonly CPos[] transitOnlyCells;
public CPos TopLeft => topLeft;
public WPos CenterPosition { get; private set; }
public WPos CenterPosition { get; }
public Building(ActorInitializer init, BuildingInfo info)
{

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
}
public int HP => hp;
public int MaxHP { get; private set; }
public int MaxHP { get; }
public bool IsDead => hp <= 0;
public bool RemoveOnDeath = true;

View File

@@ -651,7 +651,7 @@ namespace OpenRA.Mods.Common.Traits
public bool Started { get; private set; }
public int Slowdown { get; private set; }
public bool Infinite { get; set; }
public int BuildPaletteOrder { get; private set; }
public int BuildPaletteOrder { get; }
readonly ActorInfo ai;
readonly BuildableInfo bi;

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
{
RallyPoint rp;
public string Faction { get; private set; }
public string Faction { get; }
public Production(ActorInitializer init, ProductionInfo info)
: base(info)

View File

@@ -177,9 +177,9 @@ namespace OpenRA.Mods.Common.Traits
class Arrow
{
public Sprite Sprite { get; private set; }
public double EndAngle { get; private set; }
public WAngle Direction { get; private set; }
public Sprite Sprite { get; }
public double EndAngle { get; }
public WAngle Direction { get; }
public Arrow(Sprite sprite, double endAngle, WAngle direction)
{

View File

@@ -185,8 +185,8 @@ namespace OpenRA.Mods.Common.Traits
readonly HashSet<Actor> removeActorPosition = new HashSet<Actor>();
readonly Predicate<Actor> actorShouldBeRemoved;
public WDist LargestActorRadius { get; private set; }
public WDist LargestBlockingActorRadius { get; private set; }
public WDist LargestActorRadius { get; }
public WDist LargestBlockingActorRadius { get; }
public ActorMap(World world, ActorMapInfo info)
{

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
public class ControlGroups : IControlGroups, ITick, IGameSaveTraitData
{
readonly World world;
public string[] Groups { get; private set; }
public string[] Groups { get; }
readonly List<Actor>[] controlGroups;

View File

@@ -161,15 +161,15 @@ namespace OpenRA.Mods.Common.Traits
{
}
public string Text { get; private set; }
public string Text { get; }
public EditorActionStatus Status { get; set; }
}
public class EditorActionContainer
{
public int Id { get; private set; }
public IEditorAction Action { get; private set; }
public int Id { get; }
public IEditorAction Action { get; }
public EditorActionStatus Status { get; set; }
public EditorActionContainer(int id, IEditorAction action)

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
public string ID { get; set; }
public PlayerReference Owner { get; set; }
public SubCell SubCell { get; private set; }
public SubCell SubCell { get; }
public bool Selected { get; set; }
public Color RadarColor { get; private set; }
readonly RadarColorFromTerrainInfo terrainRadarColorInfo;

View File

@@ -446,7 +446,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
class EditActorEditorAction : IEditorAction
{
public string Text { get; private set; }
public string Text { get; }
readonly IEnumerable<IEditActorHandle> handles;
readonly EditorActorLayer editorActorLayer;

View File

@@ -60,8 +60,8 @@ namespace OpenRA.Mods.Common.Widgets
PlayerRadarTerrain playerRadarTerrain;
Player currentPlayer;
public string SoundUp { get; private set; }
public string SoundDown { get; private set; }
public string SoundUp { get; }
public string SoundDown { get; }
[ObjectCreator.UseCtor]
public RadarWidget(World world, WorldRenderer worldRenderer)

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.D2k.PackageLoaders
}
}
public string Name { get; private set; }
public string Name { get; }
public IEnumerable<string> Contents => index.Keys;
readonly Stream s;

View File

@@ -22,9 +22,9 @@ namespace OpenRA.Mods.D2k.SpriteLoaders
class R8Frame : ISpriteFrame
{
public SpriteFrameType Type => SpriteFrameType.Indexed8;
public Size Size { get; private set; }
public Size FrameSize { get; private set; }
public float2 Offset { get; private set; }
public Size Size { get; }
public Size FrameSize { get; }
public float2 Offset { get; }
public byte[] Data { get; set; }
public bool DisableExportPadding => true;

View File

@@ -387,7 +387,7 @@ namespace OpenRA.Platforms.Default
bool disposed;
public uint Buffer => buffer;
public int SampleRate { get; private set; }
public int SampleRate { get; }
public OpenAlSoundSource(byte[] data, int byteCount, int channels, int sampleBits, int sampleRate)
{