Make collection-typed fields readonly where possible

also I widened them all to the relevant interface

this was done with a naive regex replace, followed by reverting lines until all
the build errors were gone; the regex was something like
s@(public|internal|protected|private) ((?:List|Dictionary)<[^=\n{]+= )@$1
readonly I$2@g
This commit is contained in:
YoshiRulz 2021-03-26 16:38:09 +10:00
parent 5dd7a66120
commit 286727eb44
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
21 changed files with 38 additions and 36 deletions

View File

@ -40,8 +40,8 @@ namespace BizHawk.Client.Common.FilterManager
{
private readonly Dictionary<string, BaseFilter> _filterNameIndex = new Dictionary<string, BaseFilter>();
public List<BaseFilter> Filters = new List<BaseFilter>();
public List<ProgramStep> Program = new List<ProgramStep>();
public readonly IList<BaseFilter> Filters = new List<BaseFilter>();
public readonly IList<ProgramStep> Program = new List<ProgramStep>();
public BaseFilter this[string name]
{

View File

@ -9,7 +9,7 @@ namespace BizHawk.Client.Common
{
internal class TempFileStateDictionary : IDictionary<int, byte[]>, IDisposable
{
private Dictionary<int, Stream> _streams = new Dictionary<int, Stream>();
private readonly IDictionary<int, Stream> _streams = new Dictionary<int, Stream>();
public byte[] this[int key]
{

View File

@ -107,8 +107,8 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
public CPCBase _machine;
public List<GameInfo> _gameInfo;
public List<GameInfo> _tapeInfo = new List<GameInfo>();
public List<GameInfo> _diskInfo = new List<GameInfo>();
public readonly IList<GameInfo> _tapeInfo = new List<GameInfo>();
public readonly IList<GameInfo> _diskInfo = new List<GameInfo>();
private SoundProviderMixer SoundMixer;

View File

@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// <summary>
/// Working list of generated tape data blocks
/// </summary>
private List<TapeDataBlock> _blocks = new List<TapeDataBlock>();
private readonly IList<TapeDataBlock> _blocks = new List<TapeDataBlock>();
/// <summary>
/// Position counter

View File

@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary>
/// Working list of generated tape data blocks
/// </summary>
private List<TapeDataBlock> _blocks = new List<TapeDataBlock>();
private readonly IList<TapeDataBlock> _blocks = new List<TapeDataBlock>();
/// <summary>
/// Position counter
@ -40,7 +40,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary>
/// Object to keep track of loops - this assumes there is only one loop at a time
/// </summary>
private List<KeyValuePair<int, int>> _loopCounter = new List<KeyValuePair<int, int>>();
private readonly IList<KeyValuePair<int, int>> _loopCounter = new List<KeyValuePair<int, int>>();
private readonly DatacorderDevice _datacorder;

View File

@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary>
/// Working list of generated tape data blocks
/// </summary>
private List<TapeDataBlock> _blocks = new List<TapeDataBlock>();
private readonly IList<TapeDataBlock> _blocks = new List<TapeDataBlock>();
/// <summary>
/// Position counter

View File

@ -159,8 +159,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public List<GameInfo> _gameInfo;
public List<GameInfo> _tapeInfo = new List<GameInfo>();
public List<GameInfo> _diskInfo = new List<GameInfo>();
public readonly IList<GameInfo> _tapeInfo = new List<GameInfo>();
public readonly IList<GameInfo> _diskInfo = new List<GameInfo>();
private SyncSoundMixer SoundMixer;

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
private static readonly byte[] Check = FTXT.E.GetBytes("FDS\x1a");
private static readonly byte[] CheckAlt = FTXT.E.GetBytes("\x01*NIN");
public List<FDSDisk> Disks = new List<FDSDisk>();
public readonly IList<FDSDisk> Disks = new List<FDSDisk>();
public byte[] ExtraData;
@ -63,7 +63,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
{
private static readonly byte[] Check = FTXT.E.GetBytes("*NINTENDO-HVC*");
public List<FDSChunk> Chunks = new List<FDSChunk>();
public readonly IList<FDSChunk> Chunks = new List<FDSChunk>();
public byte[] HeaderData;
public byte[] ExtraData;

View File

@ -43,7 +43,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
private IntPtr DllBase;
private readonly List<Symbol> SymbolsByAddr = new List<Symbol>();
private Dictionary<string, Symbol> SymbolsByName = new Dictionary<string, Symbol>();
private readonly IDictionary<string, Symbol> SymbolsByName = new Dictionary<string, Symbol>();
private readonly byte[][] data = new byte[10][];

View File

@ -22,6 +22,7 @@ using Newtonsoft.Json;
using BizHawk.Emulation.Common;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.DiscSystem;
#pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete
@ -480,7 +481,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
public bool CurrentTrayOpen { get; private set; }
public int CurrentDiscIndexMounted { get; private set; }
public List<string> HackyDiscButtons = new List<string>();
public readonly IList<string> HackyDiscButtons = new List<string>();
public IEmulatorServiceProvider ServiceProvider { get; private set; }

View File

@ -8,8 +8,8 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
{
public class PSF
{
public Dictionary<string, string> TagsDictionary = new Dictionary<string, string>();
public List<string> LooseTags = new List<string>();
public readonly IDictionary<string, string> TagsDictionary = new Dictionary<string, string>();
public readonly IList<string> LooseTags = new List<string>();
public byte[] Data;
public byte[] LibData;

View File

@ -83,7 +83,7 @@ namespace BizHawk.Emulation.Cores
/// <summary>
/// extra information which could be easily gotten during the file ID (region, suspected homebrew, CRC invalid, etc.)
/// </summary>
public Dictionary<string, object> ExtraInfo = new Dictionary<string, object>();
public readonly IDictionary<string, object> ExtraInfo = new Dictionary<string, object>();
}
public class FileIDResults : List<FileIDResult>

View File

@ -37,7 +37,7 @@ namespace BizHawk.Emulation.Cores.Libretro
/// <summary>
/// Variables defined by the core
/// </summary>
public Dictionary<string, VariableDescription> Variables = new Dictionary<string, VariableDescription>();
public readonly IDictionary<string, VariableDescription> Variables = new Dictionary<string, VariableDescription>();
}
public class VariableDescription

View File

@ -60,7 +60,7 @@ namespace BizHawk.Emulation.DiscSystem
/// <summary>
/// Free-form optional memos about the disc
/// </summary>
public Dictionary<string, object> Memos = new Dictionary<string, object>();
public readonly IDictionary<string, object> Memos = new Dictionary<string, object>();
public void Dispose()
{
@ -104,7 +104,7 @@ namespace BizHawk.Emulation.DiscSystem
/// <summary>
/// Disposable resources (blobs, mostly) referenced by this disc
/// </summary>
internal List<IDisposable> DisposableResources = new List<IDisposable>();
internal readonly IList<IDisposable> DisposableResources = new List<IDisposable>();
/// <summary>
/// The sectors on the disc. Don't use this directly! Use the SectorSynthProvider instead.

View File

@ -229,7 +229,7 @@ namespace BizHawk.Emulation.DiscSystem
public class RiffContainer_INFO : RiffContainer
{
public Dictionary<string, string> dictionary = new Dictionary<string, string>();
public readonly IDictionary<string, string> dictionary = new Dictionary<string, string>();
public RiffContainer_INFO() { type = "INFO"; }
/// <exception cref="FormatException"><paramref name="rc"/>.<see cref="RiffContainer.subchunks"/> contains a chunk that does not inherit <see cref="RiffSubchunk"/></exception>

View File

@ -39,22 +39,22 @@ namespace BizHawk.Emulation.DiscSystem
/// <summary>
/// The [Session] sections
/// </summary>
public List<CCDSession> Sessions = new List<CCDSession>();
public readonly IList<CCDSession> Sessions = new List<CCDSession>();
/// <summary>
/// The [Entry] sctions
/// </summary>
public List<CCDTocEntry> TOCEntries = new List<CCDTocEntry>();
public readonly IList<CCDTocEntry> TOCEntries = new List<CCDTocEntry>();
/// <summary>
/// The [TRACK] sections
/// </summary>
public List<CCDTrack> Tracks = new List<CCDTrack>();
public readonly IList<CCDTrack> Tracks = new List<CCDTrack>();
/// <summary>
/// The [TRACK] sections, indexed by number
/// </summary>
public Dictionary<int, CCDTrack> TracksByNumber = new Dictionary<int, CCDTrack>();
public readonly IDictionary<int, CCDTrack> TracksByNumber = new Dictionary<int, CCDTrack>();
}
/// <summary>
@ -126,7 +126,7 @@ namespace BizHawk.Emulation.DiscSystem
/// <summary>
/// The indexes specified for the track (these are 0-indexed)
/// </summary>
public Dictionary<int, int> Indexes = new Dictionary<int, int>();
public readonly IDictionary<int, int> Indexes = new Dictionary<int, int>();
}
/// <summary>

View File

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common;
@ -104,11 +105,11 @@ namespace BizHawk.Emulation.DiscSystem.CUE
public CueTrackFlags Flags = CueTrackFlags.None;
public CueTrackType TrackType = CueTrackType.Unknown;
public List<CompiledCueIndex> Indexes = new List<CompiledCueIndex>();
public readonly IList<CompiledCueIndex> Indexes = new List<CompiledCueIndex>();
public override string ToString()
{
var idx = Indexes.Find((i) => i.Number == 1);
var idx = Indexes.FirstOrDefault(cci => cci.Number == 1);
if (idx.Number != 1) return $"T#{Number:D2} NO INDEX 1";
var indexlist = string.Join("|", Indexes);
return $"T#{Number:D2} {BlobIndex}:{idx.FileMSF} ({indexlist})";

View File

@ -63,7 +63,7 @@ namespace BizHawk.Emulation.DiscSystem
return true;
} //Parse()
public List<Entry> Entries = new List<Entry>();
public readonly IList<Entry> Entries = new List<Entry>();
public void Rebase(string basepath)
{

View File

@ -35,12 +35,12 @@ namespace BizHawk.Emulation.DiscSystem
/// <summary>
/// List of MDS session blocks
/// </summary>
public List<ASession> Sessions = new List<ASession>();
public readonly IList<ASession> Sessions = new List<ASession>();
/// <summary>
/// List of track blocks
/// </summary>
public List<ATrack> Tracks = new List<ATrack>();
public readonly IList<ATrack> Tracks = new List<ATrack>();
/// <summary>
/// Current parsed session objects
@ -50,7 +50,7 @@ namespace BizHawk.Emulation.DiscSystem
/// <summary>
/// Calculated MDS TOC entries (still to be parsed into BizHawk)
/// </summary>
public List<ATOCEntry> TOCEntries = new List<ATOCEntry>();
public readonly IList<ATOCEntry> TOCEntries = new List<ATOCEntry>();
}

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.DiscSystem.SBI
/// <summary>
/// a list of patched ABAs
/// </summary>
public List<int> ABAs = new List<int>();
public readonly IList<int> ABAs = new List<int>();
/// <summary>
/// 12 values (Q subchannel data) for every patched ABA; -1 means unpatched

View File

@ -13,7 +13,7 @@ namespace BizHawk.Emulation.DiscSystem
/// This is a 1-indexed list of sessions (session 1 is at [1])
/// Support for multiple sessions is thoroughly not working yet
/// </summary>
public List<Session> Sessions = new List<Session>();
public readonly IList<Session> Sessions = new List<Session>();
public class Session
{
@ -43,7 +43,7 @@ namespace BizHawk.Emulation.DiscSystem
/// For a disc with "3 tracks", Tracks.Count will be 5: it includes that lead-in track as well as the leadout track.
/// Perhaps we should turn this into a special collection type with no Count or Length, or a method to GetTrack()
/// </summary>
public List<Track> Tracks = new List<Track>();
public readonly IList<Track> Tracks = new List<Track>();
/// <summary>
/// A reference to the first information track (Track 1)