Make all collections readonly in API surface

This commit is contained in:
YoshiRulz 2022-03-01 11:09:27 +10:00
parent 8b07f9ecde
commit 5f3199acf3
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
5 changed files with 14 additions and 22 deletions

View File

@ -111,7 +111,7 @@ namespace BizHawk.Client.Common
return null;
}
public Dictionary<string, ulong> GetRegisters()
public IReadOnlyDictionary<string, ulong> GetRegisters()
{
try
{

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
@ -73,23 +72,16 @@ namespace BizHawk.Client.Common
_movieSession.Movie.Save();
}
public Dictionary<string, string> GetHeader()
{
var table = new Dictionary<string, string>();
if (_movieSession.Movie.NotActive())
{
return table;
}
foreach (var (k, v) in _movieSession.Movie.HeaderEntries) table[k] = v;
return table;
}
public IReadOnlyDictionary<string, string> GetHeader()
=> _movieSession.Movie.NotActive()
? new Dictionary<string, string>()
: _movieSession.Movie.HeaderEntries.ToDictionary(static kvp => kvp.Key, static kvp => kvp.Value);
public List<string> GetComments() => _movieSession.Movie.Comments.ToList();
public IReadOnlyList<string> GetComments()
=> _movieSession.Movie.Comments.ToList();
public List<string> GetSubtitles() =>
_movieSession.Movie.Subtitles
.Select(s => s.ToString())
.ToList();
public IReadOnlyList<string> GetSubtitles()
=> _movieSession.Movie.Subtitles.Select(static s => s.ToString()).ToList();
public string Filename() => _movieSession.Movie.Filename;

View File

@ -13,7 +13,7 @@ namespace BizHawk.Client.Common
int FrameCount();
object Disassemble(uint pc, string name = "");
ulong? GetRegister(string name);
Dictionary<string, ulong> GetRegisters();
IReadOnlyDictionary<string, ulong> GetRegisters();
void SetRegister(string register, int value);
long TotalExecutedCycles();
string GetSystemId();

View File

@ -21,8 +21,8 @@ namespace BizHawk.Client.Common
void SetRerecordCounting(bool counting);
void Stop();
double GetFps();
Dictionary<string, string> GetHeader();
List<string> GetComments();
List<string> GetSubtitles();
IReadOnlyDictionary<string, string> GetHeader();
IReadOnlyList<string> GetComments();
IReadOnlyList<string> GetSubtitles();
}
}

View File

@ -36,7 +36,7 @@ namespace BizHawk.Client.Common
public IEnumerable<T> EnumerateValues<T>(LuaTable table) => table.Values.Cast<T>();
public LuaTable ListToTable<T>(IList<T> list, int indexFrom = 1)
public LuaTable ListToTable<T>(IReadOnlyList<T> list, int indexFrom = 1)
{
var table = _lua.NewTable();
for (int i = 0, l = list.Count; i != l; i++) table[indexFrom + i] = list[i];