mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-10-24 14:05:42 +00:00
Simplify some exception throwing logic
This commit is contained in:
1 parent
959030f404
commit
c191639a24
5 files changed
+6
-31
No files matched your search
@@ -34,11 +34,7 @@ namespace EightBit
|
||||
ArgumentNullException.ThrowIfNullOrEmpty(line);
|
||||
|
||||
var requiredLength = 9 + 2 + (count * 2);
|
||||
if (line.Length != requiredLength)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(line), "Invalid hex file: line is not the required length");
|
||||
}
|
||||
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(line.Length, requiredLength, nameof(line));
|
||||
var data = new byte[count];
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
@@ -55,10 +51,7 @@ namespace EightBit
|
||||
ArgumentNullException.ThrowIfNullOrEmpty(line);
|
||||
|
||||
var colon = line[..1];
|
||||
if (colon != ":")
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(line), "Invalid hex file: line does not begin with a colon");
|
||||
}
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(colon, ":", nameof(line));
|
||||
|
||||
var countString = line.Substring(1, 2);
|
||||
var count = Convert.ToByte(countString, 16);
|
||||
|
||||
@@ -20,12 +20,7 @@ namespace SM83.HarteTest
|
||||
public Cycle(List<object> input)
|
||||
{
|
||||
Debug.Assert(input is not null, "input cannot be null");
|
||||
|
||||
if (input.Count != 3)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(input), input, "Cycles can only have three elements");
|
||||
}
|
||||
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(input.Count, 3, nameof(input));
|
||||
this.Address = AsElement(input[0]).GetUInt16();
|
||||
this.Value = AsElement(input[1]).GetByte();
|
||||
|
||||
|
||||
@@ -20,12 +20,7 @@ namespace M6502.HarteTest
|
||||
public Cycle(List<object> input)
|
||||
{
|
||||
Debug.Assert(input is not null, "input cannot be null");
|
||||
|
||||
if (input.Count != 3)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(input), input, "Cycles can only have three elements");
|
||||
}
|
||||
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(input.Count, 3, nameof(input));
|
||||
this.Address = AsElement(input[0]).GetUInt16();
|
||||
this.Value = AsElement(input[1]).GetByte();
|
||||
this.Type = AsElement(input[2]).GetString();
|
||||
|
||||
@@ -43,10 +43,7 @@
|
||||
public string GetPropertyNameFromEntryName(string name)
|
||||
{
|
||||
var found = this._entriesToProperties.TryGetValue(name, out var propertyName);
|
||||
if (!found)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(name), name, "Missing property mapping");
|
||||
}
|
||||
ArgumentOutOfRangeException.ThrowIfEqual(found, false, nameof(name));
|
||||
Debug.Assert(propertyName is not null);
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,7 @@
|
||||
public Cycle(List<object> input)
|
||||
{
|
||||
Debug.Assert(input is not null, "input cannot be null");
|
||||
|
||||
if (input.Count != 3)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(input), input, "Cycles can only have three elements");
|
||||
}
|
||||
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(input.Count, 3, nameof(input));
|
||||
this.Address = AsElement(input[0]).GetUInt16();
|
||||
if (input[1] is not null)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user