Enable MA0015 and fix noncompliance

"Specify the parameter name in ArgumentException"
needed to update package because this rule was broken until now
This commit is contained in:
YoshiRulz 2022-07-20 05:57:51 +10:00
parent 92c4714be1
commit 697c10e3e6
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
42 changed files with 84 additions and 233 deletions

View File

@ -32,7 +32,7 @@
<ItemGroup>
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.59" PrivateAssets="all" />
<PackageReference Include="Menees.Analyzers" Version="3.0.8" PrivateAssets="all" />
<PackageReference Include="Meziantou.Analyzer" Version="1.0.704" PrivateAssets="all" />
<PackageReference Include="Meziantou.Analyzer" Version="1.0.707" PrivateAssets="all" />
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
<Analyzer Include="$(ProjectDir)../../References/BizHawk.Analyzer.dll" />

View File

@ -156,7 +156,7 @@
<Rule Id="MA0014" Action="Error" />
<!-- Specify the parameter name in ArgumentException -->
<Rule Id="MA0015" Action="Hidden" />
<Rule Id="MA0015" Action="Error" />
<!-- Prefer returning collection abstraction instead of implementation -->
<Rule Id="MA0016" Action="Hidden" />

View File

@ -172,7 +172,7 @@ let
];
since-2_8_1 = [
({ name = "Menees.Analyzers"; version = "3.0.8"; sha256 = "1apv06cmnrakaylyh85hjyn380cnj0h53j3pakyp0f4jnpgw0bgf"; })
({ name = "Meziantou.Analyzer"; version = "1.0.704"; sha256 = "13jc2jylkiikyff5dmz762gmzalzsw7k8zcs6w6dk3xspwdd8n9j"; })
({ name = "Meziantou.Analyzer"; version = "1.0.707"; sha256 = "09drs16fr0xly4k8drznw7pa5f2byjc9km0pm0c3rrhl7jsz4ds5"; })
({ name = "Microsoft.AspNetCore.App.Ref"; version = "6.0.6"; sha256 = "08pjgsq2vcsdy4vgff146izvxq5hpg02a8lvih0wcsgghv1m1qki"; })
({ name = "Nullable"; version = "1.3.1"; sha256 = "0hwrr4q22c0i056dqy3v431rxjv7md910ihz0pjsi16qxsbpw7p7"; })
({ name = "StyleCop.Analyzers"; version = "1.2.0-beta.435"; sha256 = "0dirz0av24ds2k7hgpss15y4wlhwlzz22qdjvkq0n3g3sxcckrsy"; })

View File

@ -189,10 +189,7 @@ namespace BizHawk.BizInvoke
{
throw new InvalidOperationException("This calling convention adapter was created for departure only! Pass known delegate slots when constructing to enable arrival");
}
if (!(lifetime is Delegate d))
{
throw new ArgumentException("For this calling convention adapter, lifetimes must be delegate so guest slot can be inferred");
}
if (lifetime is not Delegate d) throw new ArgumentException(message: "For this calling convention adapter, lifetimes must be delegate so guest slot can be inferred", paramName: nameof(lifetime));
if (!_slots.TryGetValue(d, out var slot))
{
throw new InvalidOperationException("All callback delegates must be registered at load");

View File

@ -141,7 +141,7 @@ namespace BizHawk.Client.Common
newReserved = new TempFileStateDictionary();
break;
default:
throw new ArgumentException("Unsupported store type for reserved states.");
throw new InvalidOperationException("Unsupported store type for reserved states.");
}
if (_reserved != null)
{

View File

@ -20,8 +20,7 @@ namespace BizHawk.Client.Common
*/
public ZwinderBuffer(IRewindSettings settings)
{
if (settings == null)
throw new ArgumentException("ZwinderBuffer's settings cannot be null.");
if (settings is null) throw new ArgumentNullException(paramName: nameof(settings));
long targetSize = settings.BufferSize * 1024 * 1024;
if (settings.TargetFrameLength < 1) throw new ArgumentException(message: nameof(IRewindSettings.TargetFrameLength) + " of provided settings is invalid", paramName: nameof(settings));
@ -50,7 +49,7 @@ namespace BizHawk.Client.Common
break;
}
default:
throw new ArgumentException("Unsupported store type for ZwinderBuffer.");
throw new ArgumentException(message: $"Unsupported {nameof(IRewindSettings.BackingStore)} type for ZwinderBuffer in provided settings.", paramName: nameof(settings));
}
if (settings.UseFixedRewindInterval)
{

View File

@ -514,7 +514,7 @@ namespace BizHawk.Client.Common
}
else
{
throw new ArgumentException($"WatchDisplayType {value} is invalid for this type of Watch");
throw new ArgumentException(message: $"WatchDisplayType {value} is invalid for this type of Watch", paramName: nameof(value));
}
}
}

View File

@ -48,7 +48,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
throw new ArgumentException($"{nameof(AviWriter)} only takes its own {nameof(CodecToken)}s!");
throw new ArgumentException(message: $"{nameof(AviWriter)} only takes its own {nameof(CodecToken)}s!", paramName: nameof(token));
}
}

View File

@ -231,7 +231,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
throw new ArgumentException($"{nameof(FFmpegWriter)} can only take its own codec tokens!");
throw new ArgumentException(message: $"{nameof(FFmpegWriter)} can only take its own codec tokens!", paramName: nameof(token));
}
}

View File

@ -98,7 +98,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
throw new ArgumentException($"{nameof(GifWriter)} only takes its own tokens!");
throw new ArgumentException(message: $"{nameof(GifWriter)} only takes its own tokens!", paramName: nameof(token));
}
}

View File

@ -169,7 +169,7 @@ namespace BizHawk.Client.EmuHawk
{
if (!f.CanWrite)
{
throw new ArgumentException($"{nameof(Stream)} must be writable!");
throw new ArgumentException(message: $"{nameof(Stream)} must be writable!", paramName: nameof(f));
}
_f = f;
@ -323,11 +323,7 @@ namespace BizHawk.Client.EmuHawk
/// </summary>
private void WriteVar(int v)
{
if (v < 0)
{
throw new ArgumentException("length cannot be less than 0!");
}
if (v < 0) throw new ArgumentException(message: "length cannot be less than 0!", paramName: nameof(v));
WriteVar((ulong)v);
}
@ -542,7 +538,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
throw new ArgumentException("codec token must be of right type");
throw new ArgumentException(message: "codec token must be of right type", paramName: nameof(token));
}
}
@ -590,10 +586,10 @@ namespace BizHawk.Client.EmuHawk
{
// the sampleRate limits are arbitrary, just to catch things which are probably silly-wrong
// if a larger range of sampling rates is needed, it should be supported
if (!8000.RangeTo(96000).Contains(sampleRate) || !1.RangeTo(2).Contains(channels) || bits != 16)
{
throw new ArgumentException("Audio parameters out of range!");
}
const string ERR_MSG_INVALID_ARG = "Audio parameters out of range!";
if (sampleRate is < 8000 or > 96000) throw new ArgumentOutOfRangeException(paramName: nameof(sampleRate), sampleRate, message: ERR_MSG_INVALID_ARG);
if (channels is < 1 or > 2) throw new ArgumentOutOfRangeException(paramName: nameof(channels), channels, message: ERR_MSG_INVALID_ARG);
if (bits is not 16) throw new ArgumentException(message: ERR_MSG_INVALID_ARG, paramName: nameof(bits));
_audioSampleRate = sampleRate;
_audioChannels = channels;

View File

@ -161,7 +161,7 @@ namespace BizHawk.Client.EmuHawk
{
if (_sampleRate < 1 || _numChannels < 1)
{
throw new ArgumentException("Bad samplerate/numchannels");
throw new InvalidOperationException("Bad samplerate/numchannels");
}
}
@ -200,7 +200,7 @@ namespace BizHawk.Client.EmuHawk
// advance to first
if (!_fileChain.MoveNext())
{
throw new ArgumentException("Iterator was empty!");
throw new ArgumentException(message: "Iterator was empty!", paramName: nameof(ss));
}
OpenCurrent(ss.Current);
@ -234,15 +234,12 @@ namespace BizHawk.Client.EmuHawk
return new WavWriterVToken();
}
/// <exception cref="ArgumentOutOfRangeException"><paramref name="bits"/> is not <c>16</c></exception>
/// <exception cref="ArgumentException"><paramref name="bits"/> is not <c>16</c></exception>
public void SetAudioParameters(int sampleRate, int channels, int bits)
{
_sampleRate = sampleRate;
_channels = channels;
if (bits != 16)
{
throw new ArgumentException("Only support 16bit audio!");
}
if (bits is not 16) throw new ArgumentException(message: "Only support 16bit audio!", paramName: nameof(bits));
}
public void SetMetaData(string gameName, string authors, ulong lengthMs, ulong rerecords)

View File

@ -70,11 +70,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls
}
int count = names.Length;
if (!1.RangeTo(3).Contains(count))
{
throw new ArgumentException("Invalid number of buttons. Must be between 1 and 3.");
}
if (count is < 1 or > 3) throw new ArgumentException(message: "Invalid number of buttons. Must be between 1 and 3.", paramName: nameof(names));
//---- Set Button 1
_minButtonRowWidth += SetButtonParams(btn1, names[0], def == 1 ? 1 : 2, results[0]);

View File

@ -75,7 +75,7 @@ namespace BizHawk.Client.EmuHawk
{
if (!typeof(IToolForm).IsAssignableFrom(toolType))
{
throw new ArgumentException($"Type {toolType.Name} does not implement {nameof(IToolForm)}.");
throw new ArgumentException(message: $"Type {toolType.Name} does not implement {nameof(IToolForm)}.", paramName: nameof(toolType));
}
var mi = typeof(ToolManager).GetMethod(nameof(Load), new[] { typeof(bool), typeof(string) })!.MakeGenericMethod(toolType);
return (IToolForm) mi.Invoke(this, new object[] { focus, "" });

View File

@ -17,7 +17,7 @@ namespace BizHawk.Common
private static MethodInfo FromExpression(Expression e)
=> e is MethodCallExpression caller
? caller.Method
: throw new ArgumentException("Expression must be a method call");
: throw new ArgumentException(message: "Expression must be a method call", paramName: nameof(e));
private static MethodInfo Method<T>(Expression<Action<T>> f)
{

View File

@ -22,7 +22,7 @@ namespace BizHawk.Common
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var valueStr = value?.ToString() ?? throw new ArgumentException($"got null {nameof(value)}");
var valueStr = value?.ToString() ?? throw new ArgumentNullException(paramName: nameof(value));
return Enum.Parse(
enumType,
enumType.GetFields(BindingFlags.Public | BindingFlags.Static)
@ -33,7 +33,7 @@ namespace BizHawk.Common
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType)
{
var fieldName = Enum.GetName(enumType, value ?? throw new ArgumentException($"got null {nameof(value)}"));
var fieldName = Enum.GetName(enumType, value ?? throw new ArgumentNullException(paramName: nameof(value)));
if (fieldName != null)
{
var fieldInfo = enumType.GetField(fieldName);

View File

@ -96,9 +96,9 @@ namespace BizHawk.Common.PathExtensions
var path = new StringBuilder(260 /* = MAX_PATH */);
return Win32Imports.PathRelativePathTo(path, fromPath, GetPathAttribute(fromPath), toPath, GetPathAttribute(toPath))
? path.ToString()
: throw new ArgumentException("Paths must have a common prefix");
}
: throw new ArgumentException(message: "Paths must have a common prefix", paramName: nameof(toPath));
}
/// <returns>absolute path (OS-dependent) equivalent to <paramref name="path"/></returns>
/// <remarks>
/// unless <paramref name="cwd"/> is given, uses <see cref="CWDHacks.Get">CWDHacks.Get</see>/<see cref="Environment.CurrentDirectory">Environment.CurrentDirectory</see>,

View File

@ -15,10 +15,7 @@ namespace BizHawk.Emulation.Common.Base_Implementations
/// <exception cref="ArgumentException"><paramref name="mode"/> is not <see cref="SyncSoundMode.Sync"/></exception>
public void SetSyncMode(SyncSoundMode mode)
{
if (mode != SyncSoundMode.Sync)
{
throw new ArgumentException("Only supports Sync mode");
}
if (mode is not SyncSoundMode.Sync) throw new ArgumentException(message: "Only supports Sync mode", paramName: nameof(mode));
}
public SyncSoundMode SyncMode => SyncSoundMode.Sync;

View File

@ -73,7 +73,7 @@ namespace BizHawk.Emulation.Common
case LibSpeexDSP.RESAMPLER_ERR.BAD_STATE:
throw new Exception($"{nameof(LibSpeexDSP)}: Bad state");
case LibSpeexDSP.RESAMPLER_ERR.INVALID_ARG:
throw new ArgumentException($"{nameof(LibSpeexDSP)}: Bad Argument");
throw new Exception($"{nameof(LibSpeexDSP)}: Bad Argument");
case LibSpeexDSP.RESAMPLER_ERR.PTR_OVERLAP:
throw new Exception($"{nameof(LibSpeexDSP)}: Buffers cannot overlap");
}
@ -90,10 +90,7 @@ namespace BizHawk.Emulation.Common
/// <exception cref="Exception">unmanaged call failed</exception>
public SpeexResampler(Quality quality, uint rationum, uint ratioden, uint sratein, uint srateout, Action<short[], int> drainer = null, ISoundProvider input = null)
{
if (drainer != null && input != null)
{
throw new ArgumentException($"Can't autofetch without being an {nameof(ISoundProvider)}?");
}
if (drainer is not null && input is not null) throw new ArgumentException(message: $"Can't autofetch without being an {nameof(ISoundProvider)}?", paramName: nameof(input));
var err = LibSpeexDSP.RESAMPLER_ERR.SUCCESS;
_st = NativeDSP.speex_resampler_init_frac(2, rationum, ratioden, sratein, srateout, quality, ref err);

View File

@ -366,8 +366,9 @@ namespace BizHawk.Emulation.Cores.Components.M68000
case 4:
immed = ReadLong(pc); pc += 4;
return $"#${immed:X}";
default:
throw new ArgumentException(message: "Invalid size", paramName: nameof(size));
}
throw new ArgumentException("Invalid size");
}
private string DisassembleAddress(int mode, int reg, ref int pc)

View File

@ -224,7 +224,7 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
break;
case 0x3:
// Unknown opcode.
throw new ArgumentException();
throw new InvalidOperationException();
}
RegisterPC = addr;
cycles = 12;
@ -1164,7 +1164,7 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
// BEXT
if (ext != 0)
{
throw new ArgumentException(UNEXPECTED_BEXT);
throw new InvalidOperationException(UNEXPECTED_BEXT);
}
else
{

View File

@ -33,20 +33,12 @@ namespace BizHawk.Emulation.Cores.Calculators.Emu83
_memoryDomains.Add(new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
addr =>
{
if (addr < 0 || addr >= 0x10000)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return LibEmu83.TI83_ReadMemory(Context, (ushort)addr);
},
(addr, val) =>
{
if (addr < 0 || addr >= 0x10000)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
LibEmu83.TI83_WriteMemory(Context, (ushort)addr, val);
}, 1));

View File

@ -19,20 +19,12 @@ namespace BizHawk.Emulation.Cores.Calculators.TI83
var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return _cpu.ReadMemory((ushort)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
_cpu.WriteMemory((ushort)addr, value);
}, 1);

View File

@ -22,18 +22,12 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return _machine.ReadBus((ushort)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
_machine.WriteBus((ushort)addr, value);
}, 1)
};

View File

@ -15,9 +15,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// </summary>
public static int GetIntFromBitArray(BitArray bitArray)
{
if (bitArray.Length > 32)
throw new ArgumentException("Argument length shall be at most 32 bits.");
if (bitArray.Length > 32) throw new ArgumentException(message: "Argument length shall be at most 32 bits.", paramName: nameof(bitArray));
int[] array = new int[1];
bitArray.CopyTo(array, 0);
return array[0];

View File

@ -14,20 +14,12 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
var mainRamDomain = new MemoryDomainDelegate("Main Ram", 0xC000, MemoryDomain.Endian.Little,
addr =>
{
if (addr < 0 || addr >= 0xC000)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xBFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return (byte)_machine.Memory.Peek((int)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 0xC000)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xBFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
_machine.Memory.Write((int)addr, value);
}, 1);
@ -36,20 +28,12 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
addr =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return (byte)_machine.Memory.Peek((int)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
_machine.Memory.Write((int)addr, value);
}, 1);

View File

@ -22,19 +22,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return _machine.ReadBus((ushort)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
_machine.WriteBus((ushort)addr, value);
}, 1)
};

View File

@ -15,9 +15,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
public static int GetIntFromBitArray(BitArray bitArray)
{
if (bitArray.Length > 32)
throw new ArgumentException("Argument length shall be at most 32 bits.");
if (bitArray.Length > 32) throw new ArgumentException(message: "Argument length shall be at most 32 bits.", paramName: nameof(bitArray));
int[] array = new int[1];
bitArray.CopyTo(array, 0);
return array[0];

View File

@ -19,20 +19,12 @@ namespace BizHawk.Emulation.Cores.ColecoVision
new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
addr =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return _cpu.ReadMemory((ushort)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
_cpu.WriteMemory((ushort)addr, value);
}, 1)
};

View File

@ -18,19 +18,12 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF
new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Big,
(addr) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return ReadBus((ushort)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
WriteBus((ushort)addr, value);
}, 1)
};

View File

@ -83,10 +83,7 @@ namespace BizHawk.Emulation.Cores.Intellivision
crc = UpdateCRC16(crc, upper_end);
ushort start = (ushort)(upper_start << 8);
ushort end = (ushort)((upper_end << 8) | 0xFF);
if (end < start)
{
throw new ArgumentException("Ranges can't start higher than they end.");
}
if (end < start) throw new ArgumentException(message: "Ranges can't start higher than they end.", paramName: nameof(Rom));
for (int addr = start; addr <= end; addr++)
{
@ -100,10 +97,7 @@ namespace BizHawk.Emulation.Cores.Intellivision
}
expected = (ushort)((Rom[offset++] << 8) | Rom[offset++]);
if (expected != crc)
{
throw new ArgumentException("Invalid CRC.");
}
if (expected != crc) throw new ArgumentException(message: "Invalid CRC.", paramName: nameof(Rom));
}
// Parse for memory attributes.
@ -151,10 +145,7 @@ namespace BizHawk.Emulation.Cores.Intellivision
int rangeStart = range * 2048;
ushort start = (ushort)((((Rom[index] >> 4) & 0x07) << 8) + rangeStart);
ushort end = (ushort)(((Rom[index] & 0x07) << 8) + 0xFF + rangeStart);
if (end < start)
{
throw new ArgumentException("Ranges can't start higher than they end.");
}
if (end < start) throw new ArgumentException(message: "Ranges can't start higher than they end.", paramName: nameof(Rom));
FineAddresses[range] = new ushort[2];
FineAddresses[range][0] = start;
@ -170,10 +161,7 @@ namespace BizHawk.Emulation.Cores.Intellivision
expected = (ushort)((Rom[offset++] << 8) | (Rom[offset++] & 0xFF));
// Check if there is an invalid CRC for the memory attributes / fine addresses.
if (expected != crc)
{
throw new ArgumentException("Invalid CRC.");
}
if (expected != crc) throw new ArgumentException(message: "Invalid CRC.", paramName: nameof(Rom));
return offset;
}

View File

@ -307,9 +307,9 @@ namespace BizHawk.Emulation.Cores.Intellivision
return 0x75CC80;
case 15:
return 0xB51A58;
default:
throw new ArgumentOutOfRangeException(paramName: nameof(color), color, message: "Specified color does not exist.");
}
throw new ArgumentException("Specified color does not exist.");
}
public void Background(int input_row)

View File

@ -39,20 +39,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
_memoryDomains.Add(new MemoryDomainDelegate("System Bus", 65536, MemoryDomain.Endian.Little,
addr =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return LibGambatte.gambatte_cpuread(GambatteState, (ushort)addr);
},
(addr, val) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
LibGambatte.gambatte_cpuwrite(GambatteState, (ushort)addr, val);
}, 1));

View File

@ -36,13 +36,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
public void StoreSaveRam(byte[] data)
{
int expected = LibGambatte.gambatte_getsavedatalength(GambatteState);
switch (data.Length - expected)
{
case 0:
break;
default:
throw new ArgumentException("Size of saveram data does not match expected!");
}
if (data.Length != expected) throw new ArgumentException(message: "Size of saveram data does not match expected!", paramName: nameof(data));
LibGambatte.gambatte_loadsavedata(GambatteState, data);

View File

@ -209,8 +209,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
/// <param name="writeprotect">disk is write protected</param>
public void Insert(byte[] side, int bitlength, bool writeprotect)
{
if (side.Length * 8 < bitlength)
throw new ArgumentException("Disk too small for parameter!");
if (side.Length * 8 < bitlength) throw new ArgumentException(message: "Disk too small for parameter!", paramName: nameof(side));
disk = side;
disksize = bitlength;
diskpos = 0;
@ -237,8 +236,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public void ApplyDiff(byte[] data)
{
int bitsize = data[0] * 0x10000 + data[1] * 0x100 + data[2];
if (bitsize != disksize)
throw new ArgumentException("Disk size mismatch!");
if (bitsize != disksize) throw new ArgumentException(message: "Disk size mismatch!", paramName: nameof(data));
int pos = 0;
while (bitsize > 0)
{

View File

@ -34,20 +34,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
MemoryDomain.Endian.Unknown,
addr =>
{
if (addr < 0 || addr >= 0x10000)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return QN.qn_peek_prgbus(Context, (int)addr);
},
(addr, val) =>
{
if (addr < 0 || addr >= 0x10000)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
QN.qn_poke_prgbus(Context, (int)addr, val);
}, 1));

View File

@ -46,20 +46,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy
_memoryDomains.Add(new MemoryDomainDelegate("System Bus", 65536, MemoryDomain.Endian.Little,
addr =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return LibSameboy.sameboy_cpuread(SameboyState, (ushort)addr);
},
(addr, val) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
LibSameboy.sameboy_cpuwrite(SameboyState, (ushort)addr, val);
}, 1));

View File

@ -25,10 +25,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy
public void StoreSaveRam(byte[] data)
{
int expected = LibSameboy.sameboy_sramlen(SameboyState);
if (data.Length - expected != 0)
{
throw new ArgumentException("Size of saveram data does not match expected!");
}
if (data.Length != expected) throw new ArgumentException(message: "Size of saveram data does not match expected!", paramName: nameof(data));
if (expected > 0)
{

View File

@ -20,14 +20,12 @@ namespace BizHawk.Emulation.Cores.PCEngine
var systemBusDomain = new MemoryDomainDelegate("System Bus (21 bit)", 0x200000, MemoryDomain.Endian.Little,
(addr) =>
{
if (addr < 0 || addr >= 0x200000)
throw new ArgumentOutOfRangeException();
if (addr is < 0 or > 0x1FFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return Cpu.ReadMemory21((int)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 0x200000)
throw new ArgumentOutOfRangeException();
if (addr is < 0 or > 0x1FFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
Cpu.WriteMemory21((int)addr, value);
},
wordSize: 2);
@ -36,14 +34,12 @@ namespace BizHawk.Emulation.Cores.PCEngine
var cpuBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) =>
{
if (addr < 0 || addr >= 0x10000)
throw new ArgumentOutOfRangeException();
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return Cpu.PeekMemory((ushort)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 0x10000)
throw new ArgumentOutOfRangeException();
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
Cpu.PokeMemory((ushort)addr, value);
},
wordSize: 2);

View File

@ -60,7 +60,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
switch (portNum)
{
default:
throw new ArgumentException($"Invalid {nameof(portNum)}: {portNum}");
throw new ArgumentOutOfRangeException(paramName: nameof(portNum), portNum, "port index out of range");
case 1:
return _port1.Read(c, sel);
case 2:

View File

@ -19,20 +19,12 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return Cpu.ReadMemory((ushort)addr);
},
(addr, value) =>
{
if (addr < 0 || addr >= 65536)
{
throw new ArgumentOutOfRangeException();
}
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
Cpu.WriteMemory((ushort)addr, value);
}, 1)
};

View File

@ -36,15 +36,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
mm.Add(new MemoryDomainDelegate(name, size, MemoryDomain.Endian.Unknown,
addr =>
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
using (_elf.EnterExit())
return p[addr ^ 1];
},
(addr, val) =>
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();
if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
Core.gpgx_poke_vram(((int)addr) ^ 1, val);
},
wordSize: 2));
@ -62,15 +60,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
addr =>
{
var a = (uint)addr;
if (a >= 0x1000000)
throw new ArgumentOutOfRangeException();
if (a > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range");
return Core.gpgx_peek_m68k_bus(a);
},
(addr, val) =>
{
var a = (uint)addr;
if (a >= 0x1000000)
throw new ArgumentOutOfRangeException();
if (a > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range");
Core.gpgx_write_m68k_bus(a, val);
}, 2);
@ -82,15 +78,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
addr =>
{
var a = (uint)addr;
if (a >= 0x1000000)
throw new ArgumentOutOfRangeException();
if (a > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range");
return Core.gpgx_peek_s68k_bus(a);
},
(addr, val) =>
{
var a = (uint)addr;
if (a >= 0x1000000)
throw new ArgumentOutOfRangeException();
if (a > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), a, message: "address out of range");
Core.gpgx_write_s68k_bus(a, val);
}, 2);