Revert "Replace unnecessary init props w/ ctors, remove hack for init props"

This reverts commit af8a330422.

I like the `init;` feature in modern C# and see it as an improvement on constructor parameters for initializing immutable "data" classes.  Feel free to disagree in code you maintain.
This commit is contained in:
nattthebear 2021-01-15 08:47:09 -05:00
parent dd39e95be6
commit 6424e35c6a
3 changed files with 27 additions and 27 deletions

View File

@ -0,0 +1,4 @@
namespace System.Runtime.CompilerServices
{
public static class IsExternalInit {}
}

View File

@ -396,26 +396,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{
throw new InvalidOperationException("Unexpected error in gambatte_getmemoryarea");
}
return new GPUMemoryAreas(vram: _vram, oam: _oam, sppal: _sppal, bgpal: _bgpal);
return new GPUMemoryAreas
{
Vram = _vram,
Oam = _oam,
Sppal = _sppal,
Bgpal = _bgpal,
};
}
private class GPUMemoryAreas : IGPUMemoryAreas
{
public IntPtr Vram { get; }
public IntPtr Vram { get; init; }
public IntPtr Oam { get; }
public IntPtr Oam { get; init; }
public IntPtr Sppal { get; }
public IntPtr Sppal { get; init; }
public IntPtr Bgpal { get; }
public GPUMemoryAreas(IntPtr vram, IntPtr oam, IntPtr sppal, IntPtr bgpal)
{
Vram = vram;
Oam = oam;
Sppal = sppal;
Bgpal = bgpal;
}
public IntPtr Bgpal { get; init; }
public void Dispose() {}
}

View File

@ -312,11 +312,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy
_exe.Enter();
try
{
return new GPUMemoryAreas(_exe,
vram: _cachedGpuPointers[0],
oam: _cachedGpuPointers[1],
sppal: _cachedGpuPointers[3],
bgpal: _cachedGpuPointers[2]);
return new GPUMemoryAreas(_exe)
{
Vram = _cachedGpuPointers[0],
Oam = _cachedGpuPointers[1],
Sppal = _cachedGpuPointers[3],
Bgpal = _cachedGpuPointers[2]
};
}
catch
{
@ -328,21 +330,17 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy
private class GPUMemoryAreas : IGPUMemoryAreas
{
private IMonitor _monitor;
public IntPtr Vram { get; }
public IntPtr Vram { get; init; }
public IntPtr Oam { get; }
public IntPtr Oam { get; init; }
public IntPtr Sppal { get; }
public IntPtr Sppal { get; init; }
public IntPtr Bgpal { get; }
public IntPtr Bgpal { get; init; }
public GPUMemoryAreas(IMonitor monitor, IntPtr vram, IntPtr oam, IntPtr sppal, IntPtr bgpal)
public GPUMemoryAreas(IMonitor monitor)
{
_monitor = monitor;
Vram = vram;
Oam = oam;
Sppal = sppal;
Bgpal = bgpal;
}
public void Dispose()