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> <ItemGroup>
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.59" PrivateAssets="all" /> <PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.59" PrivateAssets="all" />
<PackageReference Include="Menees.Analyzers" Version="3.0.8" 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="Nullable" Version="1.3.1" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" /> <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
<Analyzer Include="$(ProjectDir)../../References/BizHawk.Analyzer.dll" /> <Analyzer Include="$(ProjectDir)../../References/BizHawk.Analyzer.dll" />

View File

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

View File

@ -172,7 +172,7 @@ let
]; ];
since-2_8_1 = [ since-2_8_1 = [
({ name = "Menees.Analyzers"; version = "3.0.8"; sha256 = "1apv06cmnrakaylyh85hjyn380cnj0h53j3pakyp0f4jnpgw0bgf"; }) ({ 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 = "Microsoft.AspNetCore.App.Ref"; version = "6.0.6"; sha256 = "08pjgsq2vcsdy4vgff146izvxq5hpg02a8lvih0wcsgghv1m1qki"; })
({ name = "Nullable"; version = "1.3.1"; sha256 = "0hwrr4q22c0i056dqy3v431rxjv7md910ihz0pjsi16qxsbpw7p7"; }) ({ name = "Nullable"; version = "1.3.1"; sha256 = "0hwrr4q22c0i056dqy3v431rxjv7md910ihz0pjsi16qxsbpw7p7"; })
({ name = "StyleCop.Analyzers"; version = "1.2.0-beta.435"; sha256 = "0dirz0av24ds2k7hgpss15y4wlhwlzz22qdjvkq0n3g3sxcckrsy"; }) ({ 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"); 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)) 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));
{
throw new ArgumentException("For this calling convention adapter, lifetimes must be delegate so guest slot can be inferred");
}
if (!_slots.TryGetValue(d, out var slot)) if (!_slots.TryGetValue(d, out var slot))
{ {
throw new InvalidOperationException("All callback delegates must be registered at load"); throw new InvalidOperationException("All callback delegates must be registered at load");

View File

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

View File

@ -20,8 +20,7 @@ namespace BizHawk.Client.Common
*/ */
public ZwinderBuffer(IRewindSettings settings) public ZwinderBuffer(IRewindSettings settings)
{ {
if (settings == null) if (settings is null) throw new ArgumentNullException(paramName: nameof(settings));
throw new ArgumentException("ZwinderBuffer's settings cannot be null.");
long targetSize = settings.BufferSize * 1024 * 1024; 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)); 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; break;
} }
default: 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) if (settings.UseFixedRewindInterval)
{ {

View File

@ -514,7 +514,7 @@ namespace BizHawk.Client.Common
} }
else 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 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 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 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) 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; _f = f;
@ -323,11 +323,7 @@ namespace BizHawk.Client.EmuHawk
/// </summary> /// </summary>
private void WriteVar(int v) private void WriteVar(int v)
{ {
if (v < 0) if (v < 0) throw new ArgumentException(message: "length cannot be less than 0!", paramName: nameof(v));
{
throw new ArgumentException("length cannot be less than 0!");
}
WriteVar((ulong)v); WriteVar((ulong)v);
} }
@ -542,7 +538,7 @@ namespace BizHawk.Client.EmuHawk
} }
else 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 // 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 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) 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);
throw new ArgumentException("Audio parameters out of range!"); 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; _audioSampleRate = sampleRate;
_audioChannels = channels; _audioChannels = channels;

View File

@ -161,7 +161,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (_sampleRate < 1 || _numChannels < 1) 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 // advance to first
if (!_fileChain.MoveNext()) if (!_fileChain.MoveNext())
{ {
throw new ArgumentException("Iterator was empty!"); throw new ArgumentException(message: "Iterator was empty!", paramName: nameof(ss));
} }
OpenCurrent(ss.Current); OpenCurrent(ss.Current);
@ -234,15 +234,12 @@ namespace BizHawk.Client.EmuHawk
return new WavWriterVToken(); 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) public void SetAudioParameters(int sampleRate, int channels, int bits)
{ {
_sampleRate = sampleRate; _sampleRate = sampleRate;
_channels = channels; _channels = channels;
if (bits != 16) if (bits is not 16) throw new ArgumentException(message: "Only support 16bit audio!", paramName: nameof(bits));
{
throw new ArgumentException("Only support 16bit audio!");
}
} }
public void SetMetaData(string gameName, string authors, ulong lengthMs, ulong rerecords) 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; int count = names.Length;
if (count is < 1 or > 3) throw new ArgumentException(message: "Invalid number of buttons. Must be between 1 and 3.", paramName: nameof(names));
if (!1.RangeTo(3).Contains(count))
{
throw new ArgumentException("Invalid number of buttons. Must be between 1 and 3.");
}
//---- Set Button 1 //---- Set Button 1
_minButtonRowWidth += SetButtonParams(btn1, names[0], def == 1 ? 1 : 2, results[0]); _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)) 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); var mi = typeof(ToolManager).GetMethod(nameof(Load), new[] { typeof(bool), typeof(string) })!.MakeGenericMethod(toolType);
return (IToolForm) mi.Invoke(this, new object[] { focus, "" }); return (IToolForm) mi.Invoke(this, new object[] { focus, "" });

View File

@ -17,7 +17,7 @@ namespace BizHawk.Common
private static MethodInfo FromExpression(Expression e) private static MethodInfo FromExpression(Expression e)
=> e is MethodCallExpression caller => e is MethodCallExpression caller
? caller.Method ? 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) 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) 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( return Enum.Parse(
enumType, enumType,
enumType.GetFields(BindingFlags.Public | BindingFlags.Static) 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) 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) if (fieldName != null)
{ {
var fieldInfo = enumType.GetField(fieldName); var fieldInfo = enumType.GetField(fieldName);

View File

@ -96,7 +96,7 @@ namespace BizHawk.Common.PathExtensions
var path = new StringBuilder(260 /* = MAX_PATH */); var path = new StringBuilder(260 /* = MAX_PATH */);
return Win32Imports.PathRelativePathTo(path, fromPath, GetPathAttribute(fromPath), toPath, GetPathAttribute(toPath)) return Win32Imports.PathRelativePathTo(path, fromPath, GetPathAttribute(fromPath), toPath, GetPathAttribute(toPath))
? path.ToString() ? 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> /// <returns>absolute path (OS-dependent) equivalent to <paramref name="path"/></returns>

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> /// <exception cref="ArgumentException"><paramref name="mode"/> is not <see cref="SyncSoundMode.Sync"/></exception>
public void SetSyncMode(SyncSoundMode mode) public void SetSyncMode(SyncSoundMode mode)
{ {
if (mode != SyncSoundMode.Sync) if (mode is not SyncSoundMode.Sync) throw new ArgumentException(message: "Only supports Sync mode", paramName: nameof(mode));
{
throw new ArgumentException("Only supports Sync mode");
}
} }
public SyncSoundMode SyncMode => SyncSoundMode.Sync; public SyncSoundMode SyncMode => SyncSoundMode.Sync;

View File

@ -73,7 +73,7 @@ namespace BizHawk.Emulation.Common
case LibSpeexDSP.RESAMPLER_ERR.BAD_STATE: case LibSpeexDSP.RESAMPLER_ERR.BAD_STATE:
throw new Exception($"{nameof(LibSpeexDSP)}: Bad state"); throw new Exception($"{nameof(LibSpeexDSP)}: Bad state");
case LibSpeexDSP.RESAMPLER_ERR.INVALID_ARG: 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: case LibSpeexDSP.RESAMPLER_ERR.PTR_OVERLAP:
throw new Exception($"{nameof(LibSpeexDSP)}: Buffers cannot overlap"); throw new Exception($"{nameof(LibSpeexDSP)}: Buffers cannot overlap");
} }
@ -90,10 +90,7 @@ namespace BizHawk.Emulation.Common
/// <exception cref="Exception">unmanaged call failed</exception> /// <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) 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) if (drainer is not null && input is not null) throw new ArgumentException(message: $"Can't autofetch without being an {nameof(ISoundProvider)}?", paramName: nameof(input));
{
throw new ArgumentException($"Can't autofetch without being an {nameof(ISoundProvider)}?");
}
var err = LibSpeexDSP.RESAMPLER_ERR.SUCCESS; var err = LibSpeexDSP.RESAMPLER_ERR.SUCCESS;
_st = NativeDSP.speex_resampler_init_frac(2, rationum, ratioden, sratein, srateout, quality, ref err); _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: case 4:
immed = ReadLong(pc); pc += 4; immed = ReadLong(pc); pc += 4;
return $"#${immed:X}"; 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) private string DisassembleAddress(int mode, int reg, ref int pc)

View File

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

View File

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

View File

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

View File

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

View File

@ -15,9 +15,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// </summary> /// </summary>
public static int GetIntFromBitArray(BitArray bitArray) public static int GetIntFromBitArray(BitArray bitArray)
{ {
if (bitArray.Length > 32) if (bitArray.Length > 32) throw new ArgumentException(message: "Argument length shall be at most 32 bits.", paramName: nameof(bitArray));
throw new ArgumentException("Argument length shall be at most 32 bits.");
int[] array = new int[1]; int[] array = new int[1];
bitArray.CopyTo(array, 0); bitArray.CopyTo(array, 0);
return 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, var mainRamDomain = new MemoryDomainDelegate("Main Ram", 0xC000, MemoryDomain.Endian.Little,
addr => addr =>
{ {
if (addr < 0 || addr >= 0xC000) if (addr is < 0 or > 0xBFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
{
throw new ArgumentOutOfRangeException();
}
return (byte)_machine.Memory.Peek((int)addr); return (byte)_machine.Memory.Peek((int)addr);
}, },
(addr, value) => (addr, value) =>
{ {
if (addr < 0 || addr >= 0xC000) if (addr is < 0 or > 0xBFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
{
throw new ArgumentOutOfRangeException();
}
_machine.Memory.Write((int)addr, value); _machine.Memory.Write((int)addr, value);
}, 1); }, 1);
@ -36,20 +28,12 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, var systemBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
addr => addr =>
{ {
if (addr < 0 || addr >= 65536) if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
{
throw new ArgumentOutOfRangeException();
}
return (byte)_machine.Memory.Peek((int)addr); return (byte)_machine.Memory.Peek((int)addr);
}, },
(addr, value) => (addr, value) =>
{ {
if (addr < 0 || addr >= 65536) if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
{
throw new ArgumentOutOfRangeException();
}
_machine.Memory.Write((int)addr, value); _machine.Memory.Write((int)addr, value);
}, 1); }, 1);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -307,9 +307,9 @@ namespace BizHawk.Emulation.Cores.Intellivision
return 0x75CC80; return 0x75CC80;
case 15: case 15:
return 0xB51A58; 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) 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, _memoryDomains.Add(new MemoryDomainDelegate("System Bus", 65536, MemoryDomain.Endian.Little,
addr => addr =>
{ {
if (addr < 0 || addr >= 65536) if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
{
throw new ArgumentOutOfRangeException();
}
return LibGambatte.gambatte_cpuread(GambatteState, (ushort)addr); return LibGambatte.gambatte_cpuread(GambatteState, (ushort)addr);
}, },
(addr, val) => (addr, val) =>
{ {
if (addr < 0 || addr >= 65536) if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
{
throw new ArgumentOutOfRangeException();
}
LibGambatte.gambatte_cpuwrite(GambatteState, (ushort)addr, val); LibGambatte.gambatte_cpuwrite(GambatteState, (ushort)addr, val);
}, 1)); }, 1));

View File

@ -36,13 +36,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
public void StoreSaveRam(byte[] data) public void StoreSaveRam(byte[] data)
{ {
int expected = LibGambatte.gambatte_getsavedatalength(GambatteState); int expected = LibGambatte.gambatte_getsavedatalength(GambatteState);
switch (data.Length - expected) if (data.Length != expected) throw new ArgumentException(message: "Size of saveram data does not match expected!", paramName: nameof(data));
{
case 0:
break;
default:
throw new ArgumentException("Size of saveram data does not match expected!");
}
LibGambatte.gambatte_loadsavedata(GambatteState, 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> /// <param name="writeprotect">disk is write protected</param>
public void Insert(byte[] side, int bitlength, bool writeprotect) public void Insert(byte[] side, int bitlength, bool writeprotect)
{ {
if (side.Length * 8 < bitlength) if (side.Length * 8 < bitlength) throw new ArgumentException(message: "Disk too small for parameter!", paramName: nameof(side));
throw new ArgumentException("Disk too small for parameter!");
disk = side; disk = side;
disksize = bitlength; disksize = bitlength;
diskpos = 0; diskpos = 0;
@ -237,8 +236,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public void ApplyDiff(byte[] data) public void ApplyDiff(byte[] data)
{ {
int bitsize = data[0] * 0x10000 + data[1] * 0x100 + data[2]; int bitsize = data[0] * 0x10000 + data[1] * 0x100 + data[2];
if (bitsize != disksize) if (bitsize != disksize) throw new ArgumentException(message: "Disk size mismatch!", paramName: nameof(data));
throw new ArgumentException("Disk size mismatch!");
int pos = 0; int pos = 0;
while (bitsize > 0) while (bitsize > 0)
{ {

View File

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

View File

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

View File

@ -25,10 +25,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy
public void StoreSaveRam(byte[] data) public void StoreSaveRam(byte[] data)
{ {
int expected = LibSameboy.sameboy_sramlen(SameboyState); int expected = LibSameboy.sameboy_sramlen(SameboyState);
if (data.Length - expected != 0) if (data.Length != expected) throw new ArgumentException(message: "Size of saveram data does not match expected!", paramName: nameof(data));
{
throw new ArgumentException("Size of saveram data does not match expected!");
}
if (expected > 0) 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, var systemBusDomain = new MemoryDomainDelegate("System Bus (21 bit)", 0x200000, MemoryDomain.Endian.Little,
(addr) => (addr) =>
{ {
if (addr < 0 || addr >= 0x200000) if (addr is < 0 or > 0x1FFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
throw new ArgumentOutOfRangeException();
return Cpu.ReadMemory21((int)addr); return Cpu.ReadMemory21((int)addr);
}, },
(addr, value) => (addr, value) =>
{ {
if (addr < 0 || addr >= 0x200000) if (addr is < 0 or > 0x1FFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
throw new ArgumentOutOfRangeException();
Cpu.WriteMemory21((int)addr, value); Cpu.WriteMemory21((int)addr, value);
}, },
wordSize: 2); wordSize: 2);
@ -36,14 +34,12 @@ namespace BizHawk.Emulation.Cores.PCEngine
var cpuBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little, var cpuBusDomain = new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
(addr) => (addr) =>
{ {
if (addr < 0 || addr >= 0x10000) if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
throw new ArgumentOutOfRangeException();
return Cpu.PeekMemory((ushort)addr); return Cpu.PeekMemory((ushort)addr);
}, },
(addr, value) => (addr, value) =>
{ {
if (addr < 0 || addr >= 0x10000) if (addr is < 0 or > 0xFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
throw new ArgumentOutOfRangeException();
Cpu.PokeMemory((ushort)addr, value); Cpu.PokeMemory((ushort)addr, value);
}, },
wordSize: 2); wordSize: 2);

View File

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

View File

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

View File

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