未验证 提交 9af241a8 编写于 作者: D Dimitrios Maragkos 提交者: GitHub

Fix ca2208 errors (#1844)

* ArgumentException

* ArgumentNullException

* ArgumentOutOfRangeException

* more ArgumentException swaps

* replace null with message

* added editorconfig rule

* Add rule in StyleCop.Analyzers.ruleset instead of .editorconfig

* Fix new ca2208 violation
上级 a1a16e94
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="SyleCop Rules" ToolsVersion="15.0">
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA2208" Action="Error" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA0000" Action="Error" />
<Rule Id="SA0001" Action="None" /> <!-- XML comment analysis is disabled (default for sample projects) -->
......
......@@ -29,7 +29,7 @@ namespace System.Device.I2c
DeviceInformationCollection? deviceInformationCollection = DeviceInformation.FindAllAsync(deviceSelector).WaitForCompletion();
if (deviceInformationCollection is null || deviceInformationCollection.Count == 0)
{
throw new ArgumentException($"No I2C device exists for bus ID {settings.BusId}.", $"{nameof(settings)}.{nameof(settings.BusId)}");
throw new ArgumentException($"No I2C device exists for bus ID {settings.BusId}.", nameof(settings));
}
WinI2c.I2cDevice? winI2cDevice = WinI2c.I2cDevice.FromIdAsync(deviceInformationCollection[0].Id, winSettings).WaitForCompletion();
......
......@@ -58,7 +58,7 @@ namespace System.Device.Pwm.Channels
WinPwm.PwmPin? winPin = winController.OpenPin(channel);
if (winPin is null)
{
throw new ArgumentOutOfRangeException($"The PWM chip is unable to open a channel at index {channel}.", nameof(channel));
throw new ArgumentOutOfRangeException(nameof(channel), $"The PWM chip is unable to open a channel at index {channel}.");
}
_winController = winController;
......
......@@ -52,7 +52,7 @@ namespace System.Device.Spi
DeviceInformationCollection? deviceInformationCollection = DeviceInformation.FindAllAsync(deviceSelector).WaitForCompletion();
if (deviceInformationCollection is null || deviceInformationCollection.Count == 0)
{
throw new ArgumentException($"No SPI device exists for bus ID {settings.BusId}.", $"{nameof(settings)}.{nameof(settings.BusId)}");
throw new ArgumentException($"No SPI device exists for bus ID {settings.BusId}.", nameof(settings));
}
WinSpi.SpiDevice? winDevice = WinSpi.SpiDevice.FromIdAsync(deviceInformationCollection[0].Id, winSettings).WaitForCompletion();
......
......@@ -752,7 +752,7 @@ namespace Iot.Device.Axp192
{
if (buffer.Length != 6)
{
throw new ArgumentException(nameof(buffer));
throw new ArgumentException("Buffer must be 6 bytes long.", nameof(buffer));
}
// Address from 0x06 - 0x0B
......@@ -768,7 +768,7 @@ namespace Iot.Device.Axp192
{
if (buffer.Length != 6)
{
throw new ArgumentException(nameof(buffer));
throw new ArgumentException("Buffer must be 6 bytes long.", nameof(buffer));
}
// Address from 0x06 - 0x0B
......
......@@ -77,7 +77,7 @@ namespace Iot.Device.Bh1745
{
if (!Enum.IsDefined(typeof(InterruptStatus), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
var intReset = Read8BitsFromRegister((byte)Register.SYSTEM_CONTROL);
......@@ -99,7 +99,7 @@ namespace Iot.Device.Bh1745
{
if (!Enum.IsDefined(typeof(MeasurementTime), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
var time = Read8BitsFromRegister((byte)Register.MODE_CONTROL1);
......@@ -138,7 +138,7 @@ namespace Iot.Device.Bh1745
{
if (!Enum.IsDefined(typeof(AdcGain), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
var adcGain = Read8BitsFromRegister((byte)Register.MODE_CONTROL2);
......@@ -173,7 +173,7 @@ namespace Iot.Device.Bh1745
{
if (!Enum.IsDefined(typeof(LatchBehavior), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
var intLatch = Read8BitsFromRegister((byte)Register.INTERRUPT);
......@@ -194,7 +194,7 @@ namespace Iot.Device.Bh1745
{
if (!Enum.IsDefined(typeof(InterruptSource), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
var intSource = Read8BitsFromRegister((byte)Register.INTERRUPT);
......@@ -231,7 +231,7 @@ namespace Iot.Device.Bh1745
{
if (!Enum.IsDefined(typeof(InterruptPersistence), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
var intPersistence = Read8BitsFromRegister((byte)Register.PERSISTENCE);
......
......@@ -25,7 +25,7 @@ namespace Iot.Device.Bh1745
MeasurementTime.Ms1280 => 1280,
MeasurementTime.Ms2560 => 2560,
MeasurementTime.Ms5120 => 5120,
_ => throw new ArgumentOutOfRangeException()
_ => throw new ArgumentOutOfRangeException(nameof(time))
};
/// <summary>
......
......@@ -55,7 +55,7 @@ namespace Iot.Device.Bmxx80
{
if (!Enum.IsDefined(typeof(Sampling), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
byte status = Read8BitsFromRegister((byte)Bme280Register.CTRL_HUM);
......
......@@ -96,7 +96,7 @@ namespace Iot.Device.Bmxx80
{
if (!Enum.IsDefined(typeof(Sampling), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
var status = Read8BitsFromRegister((byte)Bme680Register.CTRL_HUM);
......@@ -126,7 +126,7 @@ namespace Iot.Device.Bmxx80
{
if (!Enum.IsDefined(typeof(Bme680HeaterProfile), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
var heaterProfile = Read8BitsFromRegister((byte)Bme680Register.CTRL_GAS_1);
......@@ -154,7 +154,7 @@ namespace Iot.Device.Bmxx80
{
if (!Enum.IsDefined(typeof(Bme680FilteringMode), value))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(value));
}
var filter = Read8BitsFromRegister((byte)Bme680Register.CONFIG);
......@@ -265,7 +265,7 @@ namespace Iot.Device.Bmxx80
{
if (!Enum.IsDefined(typeof(Bme680PowerMode), powerMode))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(powerMode));
}
var status = Read8BitsFromRegister((byte)Bme680Register.CTRL_MEAS);
......@@ -290,7 +290,7 @@ namespace Iot.Device.Bmxx80
{
if (!Enum.IsDefined(typeof(Bme680HeaterProfile), profile))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(profile));
}
// read ambient temperature for resistance calculation
......
......@@ -37,7 +37,7 @@ namespace Iot.Device.Bmxx80
{
if (!Enum.IsDefined(typeof(Bme680HeaterProfile), profile))
{
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException(nameof(profile));
}
HeaterProfile = profile;
......
......@@ -81,7 +81,7 @@ namespace Iot.Device.Card.CreditCardProcessing
{
if ((issuerAuthenticationData.Length < 8) || (issuerAuthenticationData.Length > 16))
{
throw new ArgumentException(nameof(issuerAuthenticationData), "Data needs to be more than 8 and less than 16 bytes length");
throw new ArgumentException("Data needs to be more than 8 and less than 16 bytes length", nameof(issuerAuthenticationData));
}
Span<byte> toSend = stackalloc byte[5 + issuerAuthenticationData.Length];
......@@ -115,7 +115,7 @@ namespace Iot.Device.Card.CreditCardProcessing
{
if (unpredictableNumber.Length < 8)
{
throw new ArgumentException(nameof(unpredictableNumber), "Data has to be at least 8 bytes long.");
throw new ArgumentException("Data has to be at least 8 bytes long.", nameof(unpredictableNumber));
}
Span<byte> toSend = stackalloc byte[5];
......@@ -144,7 +144,7 @@ namespace Iot.Device.Card.CreditCardProcessing
// Pin can only be 4 to C length
if ((pindigits.Length < 0x04) && (pindigits.Length > 0x0C))
{
throw new ArgumentException(nameof(pindigits), "Data can only be between 4 and 12 digits");
throw new ArgumentException("Data can only be between 4 and 12 digits", nameof(pindigits));
}
// Encode the pin
......
......@@ -925,7 +925,7 @@ namespace Iot.Device.Card.Mifare
// Total blocks where we can write = 30 * 3 = 90
if (nbBlocks > 90)
{
throw new ArgumentOutOfRangeException($"NNDEF message too large, maximum {90 * 16} bytes, current size is {nbBlocks * 16}");
throw new ArgumentOutOfRangeException(nameof(message), $"NNDEF message too large, maximum {90 * 16} bytes, current size is {nbBlocks * 16}");
}
break;
......@@ -933,7 +933,7 @@ namespace Iot.Device.Card.Mifare
// Total blocks where we can write = 30 * 3 + 8 * 15 = 210
if (nbBlocks > 210)
{
throw new ArgumentOutOfRangeException($"NNDEF message too large, maximum {210 * 16} bytes, current size is {nbBlocks * 16}");
throw new ArgumentOutOfRangeException(nameof(message), $"NNDEF message too large, maximum {210 * 16} bytes, current size is {nbBlocks * 16}");
}
break;
......@@ -941,7 +941,7 @@ namespace Iot.Device.Card.Mifare
// Total blocks where we can write = 15 * 3 = 45
if (nbBlocks > 45)
{
throw new ArgumentOutOfRangeException($"NNDEF message too large, maximum {45 * 16} bytes, current size is {nbBlocks * 16}");
throw new ArgumentOutOfRangeException(nameof(message), $"NNDEF message too large, maximum {45 * 16} bytes, current size is {nbBlocks * 16}");
}
break;
......
......@@ -354,7 +354,7 @@ namespace Iot.Device.Ccs811
{
if ((humidity.Percent < 0) || (humidity.Percent > 100))
{
throw new ArgumentException(nameof(humidity), "Humidity can only be between 0 and 100.");
throw new ArgumentException("Humidity can only be between 0 and 100.", nameof(humidity));
}
Span<byte> environment = stackalloc byte[4];
......@@ -399,12 +399,12 @@ namespace Iot.Device.Ccs811
if (!IsPpmValidThreshold(lowEquivalentCO2))
{
throw new ArgumentException(nameof(lowEquivalentCO2), $"Value can only be between 0 and {ushort.MaxValue}.");
throw new ArgumentException($"Value can only be between 0 and {ushort.MaxValue}.", nameof(lowEquivalentCO2));
}
if (!IsPpmValidThreshold(highEquivalentCO2))
{
throw new ArgumentException(nameof(highEquivalentCO2), $"Value can only be between 0 and {ushort.MaxValue}.");
throw new ArgumentException($"Value can only be between 0 and {ushort.MaxValue}.", nameof(highEquivalentCO2));
}
if (lowEquivalentCO2 > highEquivalentCO2)
......@@ -416,7 +416,7 @@ namespace Iot.Device.Ccs811
if (highEquivalentCO2 - lowEquivalentCO2 < VolumeConcentration.FromPartsPerMillion(50))
{
throw new ArgumentException(nameof(lowEquivalentCO2), $"value of {nameof(highEquivalentCO2)}-{nameof(lowEquivalentCO2)} must be more than 50.");
throw new ArgumentException($"value of {nameof(highEquivalentCO2)}-{nameof(lowEquivalentCO2)} must be more than 50.", nameof(lowEquivalentCO2));
}
Span<byte> toSend = stackalloc byte[4];
......
......@@ -35,13 +35,13 @@ namespace Iot.Device.Multiplexing
{
if (pins.Length < 2)
{
throw new ArgumentException(nameof(CharlieplexSegment), "2 or more pins must be provided.");
throw new ArgumentException("2 or more pins must be provided.", nameof(pins));
}
int charlieCount = (pins.Length * pins.Length) - pins.Length;
if (nodeCount > charlieCount)
{
throw new ArgumentException(nameof(CharlieplexSegment), $"Maximum count is {charlieCount} based on {pins.Length} pins. {nodeCount} was specified as the count.");
throw new ArgumentException($"Maximum count is {charlieCount} based on {pins.Length} pins. {nodeCount} was specified as the count.", nameof(nodeCount));
}
if (nodeCount == 0)
......
......@@ -43,7 +43,7 @@ namespace Iot.Device.Common
{
if ((dec > 99) || (dec < 0))
{
throw new ArgumentException(nameof(dec), "Value must be between 0-99.");
throw new ArgumentException("Value must be between 0-99.", nameof(dec));
}
return (byte)(((dec / 10) << 4) + (dec % 10));
......
......@@ -32,7 +32,7 @@ namespace Iot.Device.DCMotor
if (_dirPin == -1)
{
throw new ArgumentOutOfRangeException(nameof(_dirPin));
throw new ArgumentOutOfRangeException(nameof(dirpin));
}
Controller.OpenPin(_dirPin, PinMode.Output);
......
......@@ -139,7 +139,7 @@ namespace Iot.Device.Display
if (value > MaxBrightness)
{
throw new ArgumentOutOfRangeException(nameof(Brightness), $"Brightness must be between 0 and {MaxBrightness}");
throw new ArgumentOutOfRangeException(nameof(value), $"Brightness must be between 0 and {MaxBrightness}");
}
_brightness = value;
......@@ -162,9 +162,9 @@ namespace Iot.Device.Display
return;
}
if (!Enum.IsDefined(typeof(BlinkRate), _blinkRate))
if (!Enum.IsDefined(typeof(BlinkRate), value))
{
throw new ArgumentOutOfRangeException(nameof(_blinkRate));
throw new ArgumentOutOfRangeException(nameof(value));
}
_blinkRate = value;
......
......@@ -157,7 +157,7 @@ namespace Iot.Device.Display
if (digits.Length + startAddress > MaxNumberOfDigits)
{
throw new ArgumentOutOfRangeException($"{nameof(Large4Digit7SegmentDisplay)} only supports {MaxNumberOfDigits - startAddress} digits starting from address {startAddress}");
throw new ArgumentOutOfRangeException(nameof(digits), $"{nameof(Large4Digit7SegmentDisplay)} only supports {MaxNumberOfDigits - startAddress} digits starting from address {startAddress}");
}
foreach (byte digit in digits)
......@@ -253,7 +253,7 @@ namespace Iot.Device.Display
value = " " + value[0] + value.Substring(2, 2);
break;
case 5 when value[2] != ':':
throw new ArgumentException(nameof(value), $"{nameof(value)}[2] must be a ':'");
throw new ArgumentException($"{nameof(value)}[2] must be a ':'", nameof(value));
case 5:
Dots |= Dot.CenterColon;
value = value.Substring(0, 2) + value.Substring(3, 2);
......
......@@ -144,7 +144,7 @@ namespace Iot.Device.Ft4222
{
if (eventTypes == PinEventTypes.None)
{
throw new ArgumentException(nameof(eventTypes), $"{nameof(PinEventTypes.None)} is an invalid value.");
throw new ArgumentException($"{nameof(PinEventTypes.None)} is an invalid value.", nameof(eventTypes));
}
if (eventTypes.HasFlag(PinEventTypes.Falling))
......
......@@ -702,18 +702,18 @@ namespace Iot.Device.GoPiGo3
}
else
{
throw new ArgumentException(nameof(port), $"Port unsupported. Must be either {nameof(GrovePort.Grove1)} or {nameof(GrovePort.Grove2)}.");
throw new ArgumentException($"Port unsupported. Must be either {nameof(GrovePort.Grove1)} or {nameof(GrovePort.Grove2)}.", nameof(port));
}
var address = ((addr & 0x7F) << 1);
if (inBytes > GroveI2cLengthLimit)
{
throw new ArgumentException(nameof(addr), $"Read length error. Up to {GroveI2cLengthLimit} bytes can be read in a single transaction.");
throw new ArgumentException($"Read length error. Up to {GroveI2cLengthLimit} bytes can be read in a single transaction.", nameof(addr));
}
if (arrayToSend.Length > GroveI2cLengthLimit)
{
throw new ArgumentException(nameof(arrayToSend), $"Write length error. Up to {GroveI2cLengthLimit} bytes can be written in a single transaction.");
throw new ArgumentException($"Write length error. Up to {GroveI2cLengthLimit} bytes can be written in a single transaction.", nameof(arrayToSend));
}
byte[] outArray = { SpiAddress, (byte)message_type, (byte)address, inBytes, (byte)arrayToSend.Length };
......@@ -756,7 +756,7 @@ namespace Iot.Device.GoPiGo3
}
else
{
throw new ArgumentException(nameof(port), $"Port unsupported. Must be either {nameof(GrovePort.Grove1)} or {nameof(GrovePort.Grove2)}.");
throw new ArgumentException($"Port unsupported. Must be either {nameof(GrovePort.Grove1)} or {nameof(GrovePort.Grove2)}.", nameof(port));
}
byte[]? outArray = null;
......@@ -878,7 +878,7 @@ namespace Iot.Device.GoPiGo3
GrovePort.Grove1Pin2 => SpiMessageType.GetGrove1Pin2State,
GrovePort.Grove2Pin1 => SpiMessageType.GetGrove2Pin1State,
GrovePort.Grove2Pin2 => SpiMessageType.GetGrove2Pin2State,
_ => throw new ArgumentException(nameof(port), "Pin(s) unsupported. Must get one at a time."),
_ => throw new ArgumentException("Pin(s) unsupported. Must get one at a time.", nameof(port)),
};
byte[] outArray = { SpiAddress, (byte)message_type, 0, 0, 0, 0 };
......@@ -913,7 +913,7 @@ namespace Iot.Device.GoPiGo3
GrovePort.Grove1Pin2 => SpiMessageType.GetGrove1Pin2Voltage,
GrovePort.Grove2Pin1 => SpiMessageType.GetGrove2Pin1Voltage,
GrovePort.Grove2Pin2 => SpiMessageType.GetGrove2Pin2Voltage,
_ => throw new ArgumentException(nameof(port), "Pin(s) unsupported. Must get one at a time."),
_ => throw new ArgumentException("Pin(s) unsupported. Must get one at a time.", nameof(port)),
};
byte[] outArray = { SpiAddress, (byte)message_type, 0, 0, 0, 0, 0 };
......@@ -948,7 +948,7 @@ namespace Iot.Device.GoPiGo3
GrovePort.Grove1Pin2 => SpiMessageType.GetGrove1Pin2Analog,
GrovePort.Grove2Pin1 => SpiMessageType.GetGrove2Pin1Analog,
GrovePort.Grove2Pin2 => SpiMessageType.GetGrove2Pin2Analog,
_ => throw new ArgumentException(nameof(port), "Pin(s) unsupported. Must get one at a time."),
_ => throw new ArgumentException("Pin(s) unsupported. Must get one at a time.", nameof(port)),
};
byte[] outArray = { SpiAddress, (byte)message_type, 0, 0, 0, 0, 0 };
......
......@@ -54,7 +54,7 @@ namespace Iot.Device.GoPiGo3.Movements
{
if (port == MotorPort.Both)
{
throw new ArgumentException(nameof(port), "Motor class can only have 1 motor");
throw new ArgumentException("Motor class can only have 1 motor", nameof(port));
}
_goPiGo = brick;
......
......@@ -29,7 +29,7 @@ namespace Iot.Device.GoPiGo3.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported");
throw new ArgumentException("Grove port not supported", nameof(port));
}
_goPiGo = goPiGo;
......
......@@ -37,7 +37,7 @@ namespace Iot.Device.GoPiGo3.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported");
throw new ArgumentException("Grove port not supported", nameof(port));
}
_goPiGo = goPiGo;
......
......@@ -29,7 +29,7 @@ namespace Iot.Device.GoPiGo3.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported");
throw new ArgumentException("Grove port not supported", nameof(port));
}
_goPiGo = goPiGo;
......
......@@ -30,7 +30,7 @@ namespace Iot.Device.GoPiGo3.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported");
throw new ArgumentException("Grove port not supported", nameof(port));
}
_goPiGo = goPiGo;
......
......@@ -29,7 +29,7 @@ namespace Iot.Device.GoPiGo3.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported");
throw new ArgumentException("Grove port not supported", nameof(port));
}
_goPiGo = goPiGo;
......
......@@ -44,7 +44,7 @@ namespace Iot.Device.GrovePiDevice.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported");
throw new ArgumentException("Grove port not supported", nameof(port));
}
_grovePi = grovePi;
......
......@@ -48,7 +48,7 @@ namespace Iot.Device.GrovePiDevice.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported");
throw new ArgumentException("Grove port not supported", nameof(port));
}
_grovePi = grovePi;
......
......@@ -41,7 +41,7 @@ namespace Iot.Device.GrovePiDevice.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported");
throw new ArgumentException("Grove port not supported", nameof(port));
}
_grovePi = grovePi;
......
......@@ -47,7 +47,7 @@ namespace Iot.Device.GrovePiDevice.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported.");
throw new ArgumentException("Grove port not supported.", nameof(port));
}
_grovePi = grovePi;
......
......@@ -68,7 +68,7 @@ namespace Iot.Device.GrovePiDevice.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported.");
throw new ArgumentException("Grove port not supported.", nameof(port));
}
_grovePi = grovePi;
......@@ -112,7 +112,7 @@ namespace Iot.Device.GrovePiDevice.Sensors
{
if (value > 10)
{
throw new ArgumentException(nameof(Value), "Only 10 leds can be controlled, 1-10.");
throw new ArgumentException("Only 10 leds can be controlled, 1-10.", nameof(Value));
}
_grovePi.WriteCommand(GrovePiCommand.LedBarLevel, _port, _level, 0);
......@@ -128,7 +128,7 @@ namespace Iot.Device.GrovePiDevice.Sensors
{
if (led > 10)
{
throw new ArgumentException(nameof(led), "Only 10 leds can be controlled, 1-10.");
throw new ArgumentException("Only 10 leds can be controlled, 1-10.", nameof(led));
}
_grovePi.WriteCommand(GrovePiCommand.LedBarSetOneLed, _port, led, status ? (byte)1 : (byte)0);
......
......@@ -40,7 +40,7 @@ namespace Iot.Device.GrovePiDevice.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported.");
throw new ArgumentException("Grove port not supported.", nameof(port));
}
_grovePi = grovePi;
......
......@@ -47,7 +47,7 @@ namespace Iot.Device.GrovePiDevice.Sensors
{
if (!SupportedPorts.Contains(port))
{
throw new ArgumentException(nameof(port), "Grove port not supported.");
throw new ArgumentException("Grove port not supported.", nameof(port));
}
_grovePi = grovePi;
......
......@@ -55,7 +55,7 @@ namespace Iot.Device.Ili9341
{
if (spiBufferSize <= 0)
{
throw new ArgumentException(nameof(spiBufferSize), "Buffer size must be larger than 0.");
throw new ArgumentException("Buffer size must be larger than 0.", nameof(spiBufferSize));
}
_spiDevice = spiDevice;
......
......@@ -44,7 +44,7 @@ namespace Iot.Device.Ili9341
if (bm.PixelFormat != PixelFormat.Format32bppArgb)
{
throw new ArgumentException(nameof(bm), $"Pixel format {bm.PixelFormat.ToString()} not supported.");
throw new ArgumentException($"Pixel format {bm.PixelFormat.ToString()} not supported.", nameof(bm));
}
// get the pixel data and send it to the display
......@@ -69,7 +69,7 @@ namespace Iot.Device.Ili9341
if (bm.PixelFormat != PixelFormat.Format32bppArgb)
{
throw new ArgumentException(nameof(bm), $"Pixel format {bm.PixelFormat.ToString()} not supported.");
throw new ArgumentException($"Pixel format {bm.PixelFormat.ToString()} not supported.", nameof(bm));
}
// allocate the working arrays.
......
......@@ -131,7 +131,7 @@ namespace Iot.Device.DistanceSensor
{
if (count < 2 || count > 254)
{
throw new ArgumentOutOfRangeException("Count must be between 2 and 254");
throw new ArgumentOutOfRangeException(nameof(count), "Count must be between 2 and 254");
}
switch (measurementRepetition)
......@@ -179,7 +179,7 @@ namespace Iot.Device.DistanceSensor
{
if ((address & 1) == 1)
{
throw new ArgumentOutOfRangeException("Address must have 0-bit in the LSB.");
throw new ArgumentOutOfRangeException(nameof(address), "Address must have 0-bit in the LSB.");
}
// Read in the unit's serial number.
......
......@@ -53,7 +53,7 @@ namespace Iot.Device.Lm75
/// <param name="i2cDevice">The I2C device used for communication.</param>
public Lm75(I2cDevice i2cDevice)
{
_i2cDevice = i2cDevice ?? throw new ArgumentException(nameof(i2cDevice));
_i2cDevice = i2cDevice ?? throw new ArgumentNullException(nameof(i2cDevice));
Disabled = false;
}
......
......@@ -99,7 +99,7 @@ namespace Iot.Device.Lsm9Ds1
AccelerationScale.Scale04G => Max / 4,
AccelerationScale.Scale08G => Max / 8,
AccelerationScale.Scale16G => Max / 16,
_ => throw new ArgumentException(nameof(_accelerometerScale), "Value is unknown."),
_ => throw new ArgumentException("Value is unknown.", nameof(_accelerometerScale)),
};
// we have 16-bit signed number
......@@ -108,7 +108,7 @@ namespace Iot.Device.Lsm9Ds1
AngularRateScale.Scale0245Dps => Max / 245,
AngularRateScale.Scale0500Dps => Max / 500,
AngularRateScale.Scale2000Dps => Max / 2000,
_ => throw new ArgumentException(nameof(_angularRateScale), "Value is unknown."),
_ => throw new ArgumentException("Value is unknown.", nameof(_angularRateScale)),
};
/// <inheritdoc/>
......
......@@ -102,7 +102,7 @@ namespace Iot.Device.Lsm9Ds1
MagneticInductionScale.Scale08G => Max / 8,
MagneticInductionScale.Scale12G => Max / 12,
MagneticInductionScale.Scale16G => Max / 16,
_ => throw new ArgumentException(nameof(_magneticInductionScale)),
_ => throw new ArgumentException("Invalid magnetic induction scale.", nameof(_magneticInductionScale)),
};
/// <inheritdoc/>
......
......@@ -316,19 +316,17 @@ namespace Iot.Device.Max7219
{
if (buffer.Rank != 2)
{
throw new ArgumentException(nameof(buffer), $"buffer must be two dimensional.");
throw new ArgumentException($"buffer must be two dimensional.", nameof(buffer));
}
if (buffer.GetUpperBound(0) != CascadedDevices - 1)
{
throw new ArgumentException(nameof(buffer),
$"buffer upper bound ({buffer.GetUpperBound(0)}) for dimension 0 must be {CascadedDevices - 1}.");
throw new ArgumentException($"buffer upper bound ({buffer.GetUpperBound(0)}) for dimension 0 must be {CascadedDevices - 1}.", nameof(buffer));
}
if (buffer.GetUpperBound(1) != NumDigits - 1)
{
throw new ArgumentException(nameof(buffer),
$"buffer upper bound ({buffer.GetUpperBound(1)}) for dimension 1 must be {NumDigits - 1}.");
throw new ArgumentException($"buffer upper bound ({buffer.GetUpperBound(1)}) for dimension 1 must be {NumDigits - 1}.", nameof(buffer));
}
}
......
......@@ -271,7 +271,7 @@ namespace Iot.Device.Mcp25xxx
{
if (byteCount < 1)
{
throw new ArgumentException(nameof(byteCount), "Invalid number of bytes.");
throw new ArgumentException("Invalid number of bytes.", nameof(byteCount));
}
const int StackThreshold = 31; // Usually won't read more than this at a time.
......
......@@ -23,7 +23,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxFilterNumber > 5)
{
throw new ArgumentException(nameof(rxFilterNumber), $"Invalid RX Filter Number value {rxFilterNumber}.");
throw new ArgumentException($"Invalid RX Filter Number value {rxFilterNumber}.", nameof(rxFilterNumber));
}
RxFilterNumber = rxFilterNumber;
......@@ -66,7 +66,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
Address.RxF3Eid0 => 3,
Address.RxF4Eid0 => 4,
Address.RxF5Eid0 => 5,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -23,7 +23,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxFilterNumber > 5)
{
throw new ArgumentException(nameof(rxFilterNumber), $"Invalid RX Filter Number value {rxFilterNumber}.");
throw new ArgumentException($"Invalid RX Filter Number value {rxFilterNumber}.", nameof(rxFilterNumber));
}
RxFilterNumber = rxFilterNumber;
......@@ -66,7 +66,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
Address.RxF3Eid8 => 3,
Address.RxF4Eid8 => 4,
Address.RxF5Eid8 => 5,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -23,7 +23,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxFilterNumber > 5)
{
throw new ArgumentException(nameof(rxFilterNumber), $"Invalid RX Filter Number value {rxFilterNumber}.");
throw new ArgumentException($"Invalid RX Filter Number value {rxFilterNumber}.", nameof(rxFilterNumber));
}
RxFilterNumber = rxFilterNumber;
......@@ -65,7 +65,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
Address.RxF3Sidh => 3,
Address.RxF4Sidh => 4,
Address.RxF5Sidh => 5,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -31,17 +31,17 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxFilterNumber > 5)
{
throw new ArgumentException(nameof(rxFilterNumber), $"Invalid RX Filter Number value {rxFilterNumber}.");
throw new ArgumentException($"Invalid RX Filter Number value {rxFilterNumber}.", nameof(rxFilterNumber));
}
if (extendedIdentifierFilter > 3)
{
throw new ArgumentException(nameof(extendedIdentifierFilter), $"Invalid EID value {extendedIdentifierFilter}.");
throw new ArgumentException($"Invalid EID value {extendedIdentifierFilter}.", nameof(extendedIdentifierFilter));
}
if (standardIdentifierFilter > 7)
{
throw new ArgumentException(nameof(standardIdentifierFilter), $"Invalid SID value {standardIdentifierFilter}.");
throw new ArgumentException($"Invalid SID value {standardIdentifierFilter}.", nameof(standardIdentifierFilter));
}
RxFilterNumber = rxFilterNumber;
......@@ -59,7 +59,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxFilterNumber > 5)
{
throw new ArgumentException(nameof(rxFilterNumber), $"Invalid RX Filter Number value {rxFilterNumber}.");
throw new ArgumentException($"Invalid RX Filter Number value {rxFilterNumber}.", nameof(rxFilterNumber));
}
RxFilterNumber = rxFilterNumber;
......@@ -116,7 +116,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
Address.RxF3Sidl => 3,
Address.RxF4Sidl => 4,
Address.RxF5Sidl => 5,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -23,7 +23,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxMaskNumber > 1)
{
throw new ArgumentException(nameof(rxMaskNumber), $"Invalid RX Mask Number value {rxMaskNumber}.");
throw new ArgumentException($"Invalid RX Mask Number value {rxMaskNumber}.", nameof(rxMaskNumber));
}
RxMaskNumber = rxMaskNumber;
......@@ -58,7 +58,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
Address.RxM0Eid0 => 0,
Address.RxM1Eid0 => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -23,7 +23,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxMaskNumber > 1)
{
throw new ArgumentException(nameof(rxMaskNumber), $"Invalid RX Mask Number value {rxMaskNumber}.");
throw new ArgumentException($"Invalid RX Mask Number value {rxMaskNumber}.", nameof(rxMaskNumber));
}
RxMaskNumber = rxMaskNumber;
......@@ -58,7 +58,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
Address.RxM0Eid8 => 0,
Address.RxM1Eid8 => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -22,7 +22,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxMaskNumber > 1)
{
throw new ArgumentException(nameof(rxMaskNumber), $"Invalid RX Mask Number value {rxMaskNumber}.");
throw new ArgumentException($"Invalid RX Mask Number value {rxMaskNumber}.", nameof(rxMaskNumber));
}
RxMaskNumber = rxMaskNumber;
......@@ -56,7 +56,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
Address.RxM0Sidh => 0,
Address.RxM1Sidh => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -26,17 +26,17 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxMaskNumber > 1)
{
throw new ArgumentException(nameof(rxMaskNumber), $"Invalid RX Mask Number value {rxMaskNumber}.");
throw new ArgumentException($"Invalid RX Mask Number value {rxMaskNumber}.", nameof(rxMaskNumber));
}
if (extendedIdentifierMask > 3)
{
throw new ArgumentException(nameof(extendedIdentifierMask), $"Invalid EID value {extendedIdentifierMask}.");
throw new ArgumentException($"Invalid EID value {extendedIdentifierMask}.", nameof(extendedIdentifierMask));
}
if (standardIdentifierMask > 7)
{
throw new ArgumentException(nameof(standardIdentifierMask), $"Invalid SID value {standardIdentifierMask}.");
throw new ArgumentException($"Invalid SID value {standardIdentifierMask}.", nameof(standardIdentifierMask));
}
RxMaskNumber = rxMaskNumber;
......@@ -53,7 +53,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
if (rxMaskNumber > 1)
{
throw new ArgumentException(nameof(rxMaskNumber), $"Invalid RX Mask Number value {rxMaskNumber}.");
throw new ArgumentException($"Invalid RX Mask Number value {rxMaskNumber}.", nameof(rxMaskNumber));
}
RxMaskNumber = rxMaskNumber;
......@@ -94,7 +94,7 @@ namespace Iot.Device.Mcp25xxx.Register.AcceptanceFilter
{
Address.RxM0Sidl => 0,
Address.RxM1Sidl => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -24,7 +24,7 @@ namespace Iot.Device.Mcp25xxx.Register.BitTimeConfiguration
{
if (baudRatePrescaler > 0b0011_1111)
{
throw new ArgumentException(nameof(baudRatePrescaler), $"Invalid BRP value {baudRatePrescaler}.");
throw new ArgumentException($"Invalid BRP value {baudRatePrescaler}.", nameof(baudRatePrescaler));
}
BaudRatePrescaler = baudRatePrescaler;
......
......@@ -29,12 +29,12 @@ namespace Iot.Device.Mcp25xxx.Register.BitTimeConfiguration
{
if (propagationSegmentLength > 0b0000_0111)
{
throw new ArgumentException(nameof(propagationSegmentLength), $"Invalid PRSEG value {propagationSegmentLength}.");
throw new ArgumentException($"Invalid PRSEG value {propagationSegmentLength}.", nameof(propagationSegmentLength));
}
if (ps1Length > 0b0000_0111)
{
throw new ArgumentException(nameof(ps1Length), $"Invalid PHSEG1 value {ps1Length}.");
throw new ArgumentException($"Invalid PHSEG1 value {ps1Length}.", nameof(ps1Length));
}
PropagationSegmentLength = propagationSegmentLength;
......
......@@ -35,7 +35,7 @@ namespace Iot.Device.Mcp25xxx.Register.BitTimeConfiguration
{
if (ps2Length > 0b0000_0111)
{
throw new ArgumentException(nameof(ps2Length), $"Invalid PHSEG2 value {ps2Length}.");
throw new ArgumentException($"Invalid PHSEG2 value {ps2Length}.", nameof(ps2Length));
}
Ps2Length = ps2Length;
......
......@@ -28,7 +28,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
if (rxBufferNumber > 1)
{
throw new ArgumentException(nameof(rxBufferNumber), $"Invalid RX Buffer Number value {rxBufferNumber}.");
throw new ArgumentException($"Invalid RX Buffer Number value {rxBufferNumber}.", nameof(rxBufferNumber));
}
RxBufferNumber = rxBufferNumber;
......@@ -45,7 +45,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
if (rxBufferNumber > 1)
{
throw new ArgumentException(nameof(rxBufferNumber), $"Invalid RX Buffer Number value {rxBufferNumber}.");
throw new ArgumentException($"Invalid RX Buffer Number value {rxBufferNumber}.", nameof(rxBufferNumber));
}
RxBufferNumber = rxBufferNumber;
......@@ -88,7 +88,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
Address.RxB0Dlc => 0,
Address.RxB1Dlc => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid address value {address}."),
_ => throw new ArgumentException($"Invalid address value {address}.", nameof(address)),
};
/// <summary>
......
......@@ -20,12 +20,12 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
if (rxBufferNumber > 1)
{
throw new ArgumentException(nameof(rxBufferNumber), $"Invalid RX Buffer Number value {rxBufferNumber}.");
throw new ArgumentException($"Invalid RX Buffer Number value {rxBufferNumber}.", nameof(rxBufferNumber));
}
if (index > 7)
{
throw new ArgumentException(nameof(index), $"Invalid Index value {index}.");
throw new ArgumentException($"Invalid Index value {index}.", nameof(index));
}
RxBufferNumber = rxBufferNumber;
......@@ -64,7 +64,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
>= Address.RxB0D0 and <= Address.RxB0D7 => 0,
>= Address.RxB1D0 and <= Address.RxB1D7 => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid address value {address}."),
_ => throw new ArgumentException($"Invalid address value {address}.", nameof(address)),
};
/// <summary>
......
......@@ -22,7 +22,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
if (rxBufferNumber > 1)
{
throw new ArgumentException(nameof(rxBufferNumber), $"Invalid RX Buffer Number value {rxBufferNumber}.");
throw new ArgumentException($"Invalid RX Buffer Number value {rxBufferNumber}.", nameof(rxBufferNumber));
}
RxBufferNumber = rxBufferNumber;
......@@ -56,7 +56,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
Address.RxB0Eid0 => 0,
Address.RxB1Eid0 => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -22,7 +22,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
if (rxBufferNumber > 1)
{
throw new ArgumentException(nameof(rxBufferNumber), $"Invalid RX Buffer Number value {rxBufferNumber}.");
throw new ArgumentException($"Invalid RX Buffer Number value {rxBufferNumber}.", nameof(rxBufferNumber));
}
RxBufferNumber = rxBufferNumber;
......@@ -56,7 +56,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
Address.RxB0Eid8 => 0,
Address.RxB1Eid8 => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid address value: {address}."),
_ => throw new ArgumentException($"Invalid address value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -22,7 +22,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
if (rxBufferNumber > 1)
{
throw new ArgumentException(nameof(rxBufferNumber), $"Invalid RX Buffer Number value {rxBufferNumber}.");
throw new ArgumentException($"Invalid RX Buffer Number value {rxBufferNumber}.", nameof(rxBufferNumber));
}
RxBufferNumber = rxBufferNumber;
......@@ -56,7 +56,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
Address.RxB0Sidh => 0,
Address.RxB1Sidh => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -42,17 +42,17 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
if (rxBufferNumber > 1)
{
throw new ArgumentException(nameof(rxBufferNumber), $"Invalid RX Buffer Number value {rxBufferNumber}.");
throw new ArgumentException($"Invalid RX Buffer Number value {rxBufferNumber}.", nameof(rxBufferNumber));
}
if (extendedIdentifier > 3)
{
throw new ArgumentException(nameof(extendedIdentifier), $"Invalid EID value {extendedIdentifier}.");
throw new ArgumentException($"Invalid EID value {extendedIdentifier}.", nameof(extendedIdentifier));
}
if (standardIdentifier > 7)
{
throw new ArgumentException(nameof(standardIdentifier), $"Invalid SID value {standardIdentifier}.");
throw new ArgumentException($"Invalid SID value {standardIdentifier}.", nameof(standardIdentifier));
}
RxBufferNumber = rxBufferNumber;
......@@ -71,7 +71,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
if (rxBufferNumber > 1)
{
throw new ArgumentException(nameof(rxBufferNumber), $"Invalid RX Buffer Number value {rxBufferNumber}.");
throw new ArgumentException($"Invalid RX Buffer Number value {rxBufferNumber}.", nameof(rxBufferNumber));
}
RxBufferNumber = rxBufferNumber;
......@@ -129,7 +129,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageReceive
{
Address.RxB0Sidl => 0,
Address.RxB1Sidl => 1,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -45,7 +45,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value {txBufferNumber}.", nameof(txBufferNumber));
}
TxBufferNumber = txBufferNumber;
......@@ -65,7 +65,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value {txBufferNumber}.", nameof(txBufferNumber));
}
TxBufferNumber = txBufferNumber;
......@@ -158,7 +158,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
Address.TxB0Ctrl => 0,
Address.TxB1Ctrl => 1,
Address.TxB2Ctrl => 2,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -27,7 +27,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value {txBufferNumber}.", nameof(txBufferNumber));
}
TxBufferNumber = txBufferNumber;
......@@ -44,7 +44,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value {txBufferNumber}.", nameof(txBufferNumber));
}
TxBufferNumber = txBufferNumber;
......@@ -89,7 +89,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
Address.TxB0Dlc => 0,
Address.TxB1Dlc => 1,
Address.TxB2Dlc => 2,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -20,12 +20,12 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value: {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value: {txBufferNumber}.", nameof(txBufferNumber));
}
if (index > 7)
{
throw new ArgumentException(nameof(index), $"Invalid Index value: {index}.");
throw new ArgumentException($"Invalid Index value: {index}.", nameof(index));
}
TxBufferNumber = txBufferNumber;
......
......@@ -22,7 +22,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value {txBufferNumber}.", nameof(txBufferNumber));
}
TxBufferNumber = txBufferNumber;
......@@ -58,7 +58,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
Address.TxB0Eid0 => 0,
Address.TxB1Eid0 => 1,
Address.TxB2Eid0 => 2,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -22,7 +22,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value {txBufferNumber}.", nameof(txBufferNumber));
}
TxBufferNumber = txBufferNumber;
......@@ -58,7 +58,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
Address.TxB0Eid8 => 0,
Address.TxB1Eid8 => 1,
Address.TxB2Eid8 => 2,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -22,7 +22,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value {txBufferNumber}.", nameof(txBufferNumber));
}
TxBufferNumber = txBufferNumber;
......@@ -58,7 +58,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
Address.TxB0Sidh => 0,
Address.TxB1Sidh => 1,
Address.TxB2Sidh => 2,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -31,17 +31,17 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value {txBufferNumber}.", nameof(txBufferNumber));
}
if (extendedIdentifier > 3)
{
throw new ArgumentException(nameof(extendedIdentifier), $"Invalid EID value {extendedIdentifier}.");
throw new ArgumentException($"Invalid EID value {extendedIdentifier}.", nameof(extendedIdentifier));
}
if (standardIdentifier > 7)
{
throw new ArgumentException(nameof(standardIdentifier), $"Invalid SID value {standardIdentifier}.");
throw new ArgumentException($"Invalid SID value {standardIdentifier}.", nameof(standardIdentifier));
}
TxBufferNumber = txBufferNumber;
......@@ -59,7 +59,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
{
if (txBufferNumber > 2)
{
throw new ArgumentException(nameof(txBufferNumber), $"Invalid TX Buffer Number value {txBufferNumber}.");
throw new ArgumentException($"Invalid TX Buffer Number value {txBufferNumber}.", nameof(txBufferNumber));
}
TxBufferNumber = txBufferNumber;
......@@ -110,7 +110,7 @@ namespace Iot.Device.Mcp25xxx.Register.MessageTransmit
Address.TxB0Sidl => 0,
Address.TxB1Sidl => 1,
Address.TxB2Sidl => 2,
_ => throw new ArgumentException(nameof(address), $"Invalid value: {address}."),
_ => throw new ArgumentException($"Invalid value: {address}.", nameof(address)),
};
/// <summary>
......
......@@ -59,7 +59,7 @@ namespace Iot.Device.Adc
if (valueChannel == referenceChannel)
{
throw new ArgumentException(nameof(valueChannel), $"ADC differential channels must be different. {nameof(valueChannel)}: {valueChannel}; {nameof(referenceChannel)}: {referenceChannel}.");
throw new ArgumentException($"ADC differential channels must be different. {nameof(valueChannel)}: {valueChannel}; {nameof(referenceChannel)}: {referenceChannel}.", nameof(valueChannel));
}
// check if it is possible to use hardware differential because both input channels are in the same differential channel pairing
......
......@@ -42,8 +42,7 @@ namespace Iot.Device.Adc
{
if (channel < 0 || channel > channelCount - 1)
{
throw new ArgumentOutOfRangeException($"ADC channel must be within the range 0-{channelCount - 1}.",
nameof(channel));
throw new ArgumentOutOfRangeException(nameof(channel), $"ADC channel must be within the range 0-{channelCount - 1}.");
}
}
......@@ -106,7 +105,7 @@ namespace Iot.Device.Adc
if (valueChannel == referenceChannel)
{
throw new ArgumentException(nameof(valueChannel), $"ADC differential channels must be different. {nameof(valueChannel)} - {nameof(referenceChannel)}");
throw new ArgumentException($"ADC differential channels must be different. {nameof(valueChannel)} - {nameof(referenceChannel)}", nameof(valueChannel));
}
return ReadInternal(valueChannel, InputType.SingleEnded, _adcResolutionBits) -
......@@ -145,7 +144,7 @@ namespace Iot.Device.Adc
4 or 8 => (inputType == InputType.SingleEnded ? 0b1_1000 : 0b1_0000) | channelVal,
2 => (inputType == InputType.SingleEnded ? 0b1101 : 0b1001) | channelVal << 1,
1 => 0,
_ => throw new ArgumentOutOfRangeException("Unsupported Channel Count"),
_ => throw new InvalidOperationException($"Unsupported ChannelCount {ChannelCount}."),
};
// read the data from the device...
......
......@@ -42,7 +42,7 @@ namespace Iot.Device.Mhz19b
{
if (uartDevice is not { Length: > 0 })
{
throw new ArgumentException(nameof(uartDevice));
throw new ArgumentException($"{nameof(uartDevice)} can't be null or empty.", nameof(uartDevice));
}
// create serial port using the setting acc. to datasheet, pg. 7, sec. general settings
......
......@@ -22,7 +22,7 @@ namespace Iot.Device.MotorHat
2 => new MotorPins(13, 12, 11),
3 => new MotorPins(2, 3, 4),
4 => new MotorPins(7, 6, 5),
_ => throw new ArgumentException(nameof(index), $"MotorHat Motor must be between 1 and 4 inclusive. {nameof(index)}: {index}")
_ => throw new ArgumentException($"MotorHat Motor must be between 1 and 4 inclusive. {nameof(index)}: {index}", nameof(index))
};
}
}
......
......@@ -20,7 +20,7 @@ namespace Iot.Device.MotorHat
{
1 => new MotorPins(0, 1, 2),
2 => new MotorPins(5, 4, 3),
_ => throw new ArgumentException(nameof(index), $"MotorHat Motor must be either 1 or 2. {nameof(index)}: {index}")
_ => throw new ArgumentException($"MotorHat Motor must be either 1 or 2. {nameof(index)}: {index}", nameof(index))
};
}
}
......
......@@ -51,7 +51,7 @@ namespace Iot.Device.Imu
{
if (i2cDevice == null)
{
throw new ArgumentNullException($"Varible i2cDevice is null");
throw new ArgumentNullException(nameof(i2cDevice), $"Variable i2cDevice is null");
}
_i2cDevice = i2cDevice;
......@@ -376,7 +376,7 @@ namespace Iot.Device.Imu
_wakeOnMotion = true;
if (accelerometerThreshold > 1020)
{
throw new ArgumentException(nameof(accelerometerThreshold), $"Value has to be between 0mg and 1020mg");
throw new ArgumentException($"Value has to be between 0mg and 1020mg", nameof(accelerometerThreshold));
}
// LSB = 4mg
......@@ -742,7 +742,7 @@ namespace Iot.Device.Imu
{
if (readBytes.Length > 24)
{
throw new ArgumentException(nameof(readBytes), "Value must be 24 bytes or less.");
throw new ArgumentException("Value must be 24 bytes or less.", nameof(readBytes));
}
byte slvAddress = (byte)((byte)Register.I2C_SLV0_ADDR + 3 * (byte)i2cChannel);
......
......@@ -31,7 +31,7 @@ namespace Iot.Device.Nmea0183.Sentences
// Sequence number is 1-based.
if (sequence < 1 || totalSequences < sequence)
{
throw new ArgumentOutOfRangeException("Current sequence number must be smaller than total sequences");
throw new ArgumentOutOfRangeException(nameof(sequence), "Current sequence number must be smaller than total sequences");
}
TotalSequences = totalSequences;
......
......@@ -33,7 +33,7 @@ namespace Iot.Device.Nrf24l01
public byte PacketSize
{
get { return _packetSize; }
set { _packetSize = value < 0 || value > 32 ? throw new ArgumentOutOfRangeException("PacketSize needs to be in the range of 0 to 32.") : value; }
set { _packetSize = value < 0 || value > 32 ? throw new ArgumentOutOfRangeException(nameof(value), "PacketSize needs to be in the range of 0 to 32.") : value; }
}
/// <summary>
......@@ -692,12 +692,12 @@ namespace Iot.Device.Nrf24l01
if (address.Length > 5 || address.Length < 1)
{
throw new ArgumentOutOfRangeException("Array Length must less than 6.");
throw new ArgumentOutOfRangeException(nameof(address), "Array Length must less than 6.");
}
if (pipe > 1 && address.Length > 1)
{
throw new ArgumentOutOfRangeException("Array Length must equal 1 when pipe more than 1. Address equal pipe1's address the first 4 byte + one byte your custom.");
throw new ArgumentOutOfRangeException(nameof(address), "Array Length must equal 1 when pipe more than 1. Address equal pipe1's address the first 4 byte + one byte your custom.");
}
Span<byte> writeData = stackalloc byte[1 + address.Length];
......@@ -747,7 +747,7 @@ namespace Iot.Device.Nrf24l01
// Details in the Datasheet P56
if (address.Length > 5 || address.Length < 1)
{
throw new ArgumentOutOfRangeException("Array Length must less than 6.");
throw new ArgumentOutOfRangeException(nameof(address), "Array Length must less than 6.");
}
_gpio.Write(_ce, PinValue.Low);
......@@ -777,7 +777,7 @@ namespace Iot.Device.Nrf24l01
// Register: 0x05, bit[6:0]
if (channel < 0 || channel > 127)
{
throw new ArgumentOutOfRangeException("Channel needs to be in the range of 0 to 127.");
throw new ArgumentOutOfRangeException(nameof(channel), "Channel needs to be in the range of 0 to 127.");
}
_gpio.Write(_ce, PinValue.Low);
......
......@@ -520,7 +520,7 @@ namespace Iot.Device.Display
{
if ((left < 0 || left > Size.Width) || (top < 0 || top > Size.Height))
{
throw new ArgumentOutOfRangeException($"The given position is not inside the display. it's 6 raws and 84 columns");
throw new ArgumentOutOfRangeException(nameof(left), $"The given position is not inside the display. it's 6 raws and 84 columns");
}
if (_cursorVisible)
......
......@@ -176,7 +176,7 @@ namespace Iot.Device.PiJuiceDevice
if ((response[0] & 0x07) < 0 || (response[0] & 0x07) > 3)
{
throw new ArgumentOutOfRangeException("Battery temperature sensor configuration out of range");
throw new InvalidOperationException("Battery temperature sensor configuration out of range");
}
return (BatteryTemperatureSense)(response[0] & 0x07);
......@@ -278,7 +278,7 @@ namespace Iot.Device.PiJuiceDevice
int index = _usbMicroCurrentLimits.IndexOf(powerInput.UsbMicroCurrentLimit);
if (index == -1)
{
throw new ArgumentOutOfRangeException(nameof(powerInput.UsbMicroCurrentLimit));
throw new ArgumentOutOfRangeException(nameof(powerInput), $"Unsupported UsbMicroCurrentLimit {powerInput.UsbMicroCurrentLimit}.");
}
byte usbMicroLimit = (byte)(index << 3);
......@@ -286,7 +286,7 @@ namespace Iot.Device.PiJuiceDevice
index = _usbMicroDpm.IndexOf(powerInput.UsbMicroDynamicPowerManagement);
if (index == -1)
{
throw new ArgumentOutOfRangeException(nameof(powerInput.UsbMicroDynamicPowerManagement));
throw new ArgumentOutOfRangeException(nameof(powerInput), $"Unsupported UsbMicroDynamicPowerManagement {powerInput.UsbMicroDynamicPowerManagement}.");
}
byte usbMicroDPM = (byte)((index & 0x07) << 3);
......@@ -308,7 +308,7 @@ namespace Iot.Device.PiJuiceDevice
if (response[0] < 0 || response[0] > 2)
{
throw new ArgumentOutOfRangeException("Led function type out of range");
throw new ArgumentOutOfRangeException(nameof(led), "Led function type out of range");
}
return new LedConfig(
......@@ -356,7 +356,7 @@ namespace Iot.Device.PiJuiceDevice
if (response[0] < 0 || response[0] > 1)
{
throw new ArgumentOutOfRangeException("Run pin out of range.");
throw new InvalidOperationException("Run pin out of range.");
}
return (RunPin)response[0];
......
......@@ -40,7 +40,7 @@ namespace Iot.Device.PiJuiceDevice
{
if (value.TotalSeconds < 0 || value.TotalSeconds > 255)
{
throw new ArgumentOutOfRangeException(nameof(value.TotalSeconds));
throw new ArgumentOutOfRangeException(nameof(value), "TotalSeconds must be between 0 and 255.");
}
_piJuice.WriteCommand(PiJuiceCommand.PowerOff, new byte[] { (byte)value.TotalSeconds });
......@@ -65,7 +65,7 @@ namespace Iot.Device.PiJuiceDevice
{
if (!value.Disabled && (value.WakeUpPercentage.Percent < 0 || value.WakeUpPercentage.Percent > 100))
{
throw new ArgumentOutOfRangeException(nameof(value.WakeUpPercentage));
throw new ArgumentOutOfRangeException(nameof(value), "WakeUpPercentage.Percent must be between 0 and 100.");
}
_piJuice.WriteCommandVerify(PiJuiceCommand.WakeUpOnCharge, new byte[] { (byte)(value.Disabled ? 0x7F : (short)value.WakeUpPercentage.Percent) });
......@@ -88,7 +88,7 @@ namespace Iot.Device.PiJuiceDevice
{
if (value.TotalMinutes < 0 || value.TotalMinutes > 65535)
{
throw new ArgumentOutOfRangeException(nameof(value.TotalMinutes));
throw new ArgumentOutOfRangeException(nameof(value), "TotalMinutes must be between 0 and 65535.");
}
var minutes = (int)value.TotalMinutes & 0xFFFF;
......
......@@ -204,17 +204,17 @@ namespace Iot.Device.PiJuiceDevice
{
if (ledBlink.Count < 1)
{
throw new ArgumentOutOfRangeException(nameof(ledBlink.Count));
throw new ArgumentOutOfRangeException(nameof(ledBlink), $"Count must be equal or greater than 1.");
}
if (ledBlink.FirstPeriod.TotalMilliseconds is < 10 or > 2550)
{
throw new ArgumentOutOfRangeException(nameof(ledBlink.FirstPeriod));
throw new ArgumentOutOfRangeException(nameof(ledBlink), "FirstPeriod.TotalMilliseconds must be between 10 and 2550.");
}
if (ledBlink.SecondPeriod.TotalMilliseconds is < 10 or > 2550)
{
throw new ArgumentOutOfRangeException(nameof(ledBlink.SecondPeriod));
throw new ArgumentOutOfRangeException(nameof(ledBlink), "SecondPeriod.TotalMilliseconds must be between 10 and 2550.");
}
var data = new byte[9];
......
......@@ -66,12 +66,12 @@ namespace Iot.Device.Pn5180
{
if (pinBusy < 0)
{
throw new ArgumentException(nameof(pinBusy), "Value must be a legal pin number. cannot be negative.");
throw new ArgumentException("Value must be a legal pin number. cannot be negative.", nameof(pinBusy));
}
if (pinNss < 0)
{
throw new ArgumentException(nameof(pinBusy), "Value must be a legal pin number. cannot be negative.");
throw new ArgumentException("Value must be a legal pin number. cannot be negative.", nameof(pinBusy));
}
_logger = this.GetCurrentClassLogger();
......@@ -137,7 +137,7 @@ namespace Iot.Device.Pn5180
{
if (outputIdentifier.Length != 16)
{
throw new ArgumentException(nameof(outputIdentifier), "Value must be 16 bytes long");
throw new ArgumentException("Value must be 16 bytes long", nameof(outputIdentifier));
}
return ReadEeprom(EepromAddress.DieIdentifier, outputIdentifier);
......@@ -152,7 +152,7 @@ namespace Iot.Device.Pn5180
{
if (eeprom.Length != 255)
{
throw new ArgumentException(nameof(eeprom), "Size of EEPROM is 255 bytes. Value must match.");
throw new ArgumentException("Size of EEPROM is 255 bytes. Value must match.", nameof(eeprom));
}
return ReadEeprom(EepromAddress.DieIdentifier, eeprom);
......@@ -167,7 +167,7 @@ namespace Iot.Device.Pn5180
{
if (eeprom.Length != 255)
{
throw new ArgumentException(nameof(eeprom), "Size of EEPROM is 255 bytes. Value must match.");
throw new ArgumentException("Size of EEPROM is 255 bytes. Value must match.", nameof(eeprom));
}
return WriteEeprom(EepromAddress.DieIdentifier, eeprom);
......@@ -183,7 +183,7 @@ namespace Iot.Device.Pn5180
{
if ((byte)address + eeprom.Length > 255)
{
throw new ArgumentException(nameof(eeprom), "Size of EEPROM is 255 bytes. Value must 255 bytes or less.");
throw new ArgumentException("Size of EEPROM is 255 bytes. Value must 255 bytes or less.", nameof(eeprom));
}
Span<byte> dumpEeprom = stackalloc byte[3];
......@@ -216,7 +216,7 @@ namespace Iot.Device.Pn5180
{
if ((byte)address + eeprom.Length > 255)
{
throw new ArgumentException(nameof(eeprom), "Size of EEPROM is 255 bytes. Value must 255 bytes or less.");
throw new ArgumentException("Size of EEPROM is 255 bytes. Value must 255 bytes or less.", nameof(eeprom));
}
Span<byte> dumpEeprom = stackalloc byte[2 + eeprom.Length];
......@@ -264,12 +264,12 @@ namespace Iot.Device.Pn5180
{
if (toSend.Length > 260)
{
throw new ArgumentException(nameof(toSend), "Data to send can't be larger than 260 bytes");
throw new ArgumentException("Data to send can't be larger than 260 bytes", nameof(toSend));
}
if ((numberValidBitsLastByte < 1) || (numberValidBitsLastByte > 8))
{
throw new ArgumentException(nameof(numberValidBitsLastByte), "Number of valid bits in last byte can only be between 1 and 8");
throw new ArgumentException("Number of valid bits in last byte can only be between 1 and 8", nameof(numberValidBitsLastByte));
}
Span<byte> sendData = stackalloc byte[2 + toSend.Length];
......@@ -303,7 +303,7 @@ namespace Iot.Device.Pn5180
{
if (toRead.Length > 508)
{
throw new ArgumentException(nameof(toRead), "Data to read can't be larger than 508 bytes");
throw new ArgumentException("Data to read can't be larger than 508 bytes", nameof(toRead));
}
Span<byte> sendData = stackalloc byte[2];
......@@ -461,7 +461,7 @@ namespace Iot.Device.Pn5180
var card = _activeSelected.Where(m => m.Card.TargetNumber == targetNumber).FirstOrDefault();
if (card is null)
{
throw new ArgumentException(nameof(targetNumber), $"Device with target number {targetNumber} is not part of the list of selected devices. Card may have been removed.");
throw new ArgumentException($"Device with target number {targetNumber} is not part of the list of selected devices. Card may have been removed.", nameof(targetNumber));
}
Span<byte> toSend = stackalloc byte[dataToSend.Length + 2];
......@@ -642,7 +642,7 @@ namespace Iot.Device.Pn5180
{
if (!((blockNumber == 1) || (blockNumber == 0)))
{
throw new ArgumentException(nameof(blockNumber), "Value can be only 0 or 1.");
throw new ArgumentException("Value can be only 0 or 1.", nameof(blockNumber));
}
Span<byte> rBlock = new byte[2] { (byte)(0b1010_1010 | (byte)ack | blockNumber), targetNumber };
......@@ -674,17 +674,17 @@ namespace Iot.Device.Pn5180
_logger.LogDebug($"{nameof(MifareAuthenticate)}: ");
if (key.Length != 6)
{
throw new ArgumentException(nameof(key), "Value must be 6 bytes.");
throw new ArgumentException("Value must be 6 bytes.", nameof(key));
}
if (cardUid.Length != 4)
{
throw new ArgumentException(nameof(cardUid), "Value must be 4 bytes.");
throw new ArgumentException("Value must be 4 bytes.", nameof(cardUid));
}
if (!((mifareCommand == MifareCardCommand.AuthenticationA) || (mifareCommand == MifareCardCommand.AuthenticationB)))
{
throw new ArgumentException(nameof(mifareCommand), $"{nameof(MifareCardCommand.AuthenticationA)} and {nameof(MifareCardCommand.AuthenticationB)} are the only supported commands");
throw new ArgumentException($"{nameof(MifareCardCommand.AuthenticationA)} and {nameof(MifareCardCommand.AuthenticationB)} are the only supported commands", nameof(mifareCommand));
}
Span<byte> toAuthenticate = stackalloc byte[13];
......@@ -795,7 +795,7 @@ namespace Iot.Device.Pn5180
// Page 41 documentation PN5180A0XX-C3.pdf
if ((configuration.Length > 195) || (configuration.Length % 5 != 0) || (configuration.Length == 0))
{
throw new ArgumentException(nameof(configuration), "Value must be a positive multiple of 5 and no larger than 195 bytes.");
throw new ArgumentException("Value must be a positive multiple of 5 and no larger than 195 bytes.", nameof(configuration));
}
Span<byte> rfConfig = stackalloc byte[2];
......@@ -835,7 +835,7 @@ namespace Iot.Device.Pn5180
// Page 41 documentation PN5180A0XX-C3.pdf
if ((configuration.Length > 252) || (configuration.Length % 6 != 0) || (configuration.Length == 0))
{
throw new ArgumentException(nameof(configuration), "Value must be a positive multiple of 6 and no larger than 252 bytes.");
throw new ArgumentException("Value must be a positive multiple of 6 and no larger than 252 bytes.", nameof(configuration));
}
Span<byte> rfConfig = stackalloc byte[1 + configuration.Length];
......@@ -1345,7 +1345,7 @@ namespace Iot.Device.Pn5180
{
if (crc.Length != 2)
{
throw new ArgumentException(nameof(crc), $"Value must be 2 bytes.");
throw new ArgumentException($"Value must be 2 bytes.", nameof(crc));
}
var crcRet = CalculateCrc(buffer, 0xFFFF);
......@@ -1363,7 +1363,7 @@ namespace Iot.Device.Pn5180
{
if (crc.Length != 2)
{
throw new ArgumentException(nameof(crc), "Value must be 2 bytes.");
throw new ArgumentException("Value must be 2 bytes.", nameof(crc));
}
var crcRet = CalculateCrc(buffer, 0x6363);
......@@ -1390,7 +1390,7 @@ namespace Iot.Device.Pn5180
_logger.LogDebug($"{nameof(GetRxStatus)}");
if (rxStatus.Length != 4)
{
throw new ArgumentException(nameof(rxStatus), "Value must be 4 bytes.");
throw new ArgumentException("Value must be 4 bytes.", nameof(rxStatus));
}
try
......@@ -1412,7 +1412,7 @@ namespace Iot.Device.Pn5180
_logger.LogDebug($"{nameof(GetIrqStatus)}");
if (irqStatus.Length != 4)
{
throw new ArgumentException(nameof(irqStatus), "Value must be 4 bytes.");
throw new ArgumentException("Value must be 4 bytes.", nameof(irqStatus));
}
try
......@@ -1437,7 +1437,7 @@ namespace Iot.Device.Pn5180
{
if (data.Length != 4)
{
throw new ArgumentException(nameof(data), "Value must be 4 bytes.");
throw new ArgumentException("Value must be 4 bytes.", nameof(data));
}
Span<byte> toSend = stackalloc byte[2 + data.Length];
......
......@@ -31,7 +31,7 @@ namespace Iot.Device.Pn532.AsTarget
{
if (value.Length != _nfcId2.Length)
{
throw new ArgumentException(nameof(NfcId2), $"Value must be {_nfcId2.Length} bytes.");
throw new ArgumentException($"Value must be {_nfcId2.Length} bytes.", nameof(NfcId2));
}
value.CopyTo(_nfcId2, 0);
......@@ -51,7 +51,7 @@ namespace Iot.Device.Pn532.AsTarget
{
if (value.Length != _pad.Length)
{
throw new ArgumentException(nameof(Pad), $"Value must be {_pad.Length} bytes.");
throw new ArgumentException($"Value must be {_pad.Length} bytes.", nameof(Pad));
}
value.CopyTo(_pad, 0);
......@@ -72,7 +72,7 @@ namespace Iot.Device.Pn532.AsTarget
{
if (value.Length != _systemCode.Length)
{
throw new ArgumentException(nameof(SystemCode), $"Value must be {_systemCode.Length} bytes.");
throw new ArgumentException($"Value must be {_systemCode.Length} bytes.", nameof(SystemCode));
}
value.CopyTo(_systemCode, 0);
......
......@@ -25,7 +25,7 @@ namespace Iot.Device.Pn532.AsTarget
{
if (value.Length != _atqa.Length)
{
throw new ArgumentException(nameof(Atqa), $"Value must be {_atqa.Length} bytes.");
throw new ArgumentException($"Value must be {_atqa.Length} bytes.", nameof(Atqa));
}
value.CopyTo(_atqa, 0);
......@@ -44,7 +44,7 @@ namespace Iot.Device.Pn532.AsTarget
{
if (value.Length != _nfcId3.Length)
{
throw new ArgumentException(nameof(NfcId3), $"Value must be {_nfcId3.Length} bytes.");
throw new ArgumentException($"Value must be {_nfcId3.Length} bytes.", nameof(NfcId3));
}
value.CopyTo(_nfcId3, 0);
......
......@@ -28,7 +28,7 @@ namespace Iot.Device.Pn532.AsTarget
{
if (value.Length != _nfcId3.Length)
{
throw new ArgumentException(nameof(NfcId3), $"Value must be {_nfcId3.Length} bytes.");
throw new ArgumentException($"Value must be {_nfcId3.Length} bytes.", nameof(NfcId3));
}
value.CopyTo(_nfcId3, 0);
......@@ -46,7 +46,7 @@ namespace Iot.Device.Pn532.AsTarget
{
if (value.Length > 47)
{
throw new ArgumentException(nameof(GeneralTarget), "Value must be less than 47 bytes.");
throw new ArgumentException("Value must be less than 47 bytes.", nameof(GeneralTarget));
}
_generalTarget = new byte[value.Length];
......@@ -64,7 +64,7 @@ namespace Iot.Device.Pn532.AsTarget
{
if (value.Length > 48)
{
throw new ArgumentException(nameof(HistoricalTarget), "Value must be less than 48 bytes.");
throw new ArgumentException("Value must be less than 48 bytes.", nameof(HistoricalTarget));
}
_historicalTarget = new byte[value.Length];
......
......@@ -387,7 +387,7 @@ namespace Iot.Device.Pn532
// The maximum value for the timeout is 12.75 sec (Timeout = 0xFF).
if (value / 50 > 0xFF)
{
throw new ArgumentException(nameof(VirtualCardTimeout), "Value must be 12750 milliseconds or less.");
throw new ArgumentException("Value must be 12750 milliseconds or less.", nameof(VirtualCardTimeout));
}
_virtualCardTimeout = value / 50;
......
......@@ -139,7 +139,7 @@ namespace Iot.Device.RadioReceiver
break;
default:
throw new ArgumentOutOfRangeException(nameof(FrequencyRange), FrequencyRange, null);
throw new InvalidOperationException($"Unsupported FrequencyRange {FrequencyRange}.");
}
int f = (int)((frequencyMhz * 1000000 + 225000) / 8192);
......
......@@ -107,7 +107,7 @@ namespace Iot.Device.RadioTransmitter
// Details in Datasheet P7
if (frequency < 70 || frequency > 108)
{
throw new ArgumentOutOfRangeException("Range from 70MHz to 108MHz.");
throw new ArgumentOutOfRangeException(nameof(frequency), "Range from 70MHz to 108MHz.");
}
int freq, reg0, reg1, reg2;
......
......@@ -24,7 +24,7 @@ namespace Iot.Device.Seesaw
if (pin < 2 || pin > 5)
{
throw new ArgumentOutOfRangeException("ADC pin must be within 2-5 range.");
throw new ArgumentOutOfRangeException(nameof(pin), "ADC pin must be within 2-5 range.");
}
return BinaryPrimitives.ReadUInt16BigEndian(Read(SeesawModule.Adc, SeesawFunction.AdcChannelOffset + pin - 2, 2, AdcConversionDelayMicroseconds));
......
......@@ -18,7 +18,7 @@ namespace Iot.Device.Seesaw
{
if (pin < 0 || pin > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pin), "Gpio pin must be within 0-63 range.");
}
SetGpioPinModeBulk((ulong)(1 << pin), mode);
......@@ -73,7 +73,7 @@ namespace Iot.Device.Seesaw
{
if (pin > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pin), "Gpio pin must be within 0-63 range.");
}
WriteGpioDigitalBulk((ulong)(1 << pin), value);
......@@ -103,7 +103,7 @@ namespace Iot.Device.Seesaw
{
if (pin > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pin), "Gpio pin must be within 0-63 range.");
}
return ((ReadGpioDigitalBulk((ulong)(1 << pin))) != 0);
......
......@@ -58,7 +58,7 @@ namespace Iot.Device.Seesaw
{
if (pinNumber < 0 || pinNumber > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pinNumber), "Gpio pin must be within 0-63 range.");
}
if (!IsPinOpen(pinNumber))
......@@ -78,7 +78,7 @@ namespace Iot.Device.Seesaw
{
if (pinNumber < 0 || pinNumber > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pinNumber), "Gpio pin must be within 0-63 range.");
}
if (!IsPinOpen(pinNumber))
......@@ -100,7 +100,7 @@ namespace Iot.Device.Seesaw
{
if (pinNumber < 0 || pinNumber > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pinNumber), "Gpio pin must be within 0-63 range.");
}
return true;
......@@ -115,7 +115,7 @@ namespace Iot.Device.Seesaw
{
if (pinNumber < 0 || pinNumber > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pinNumber), "Gpio pin must be within 0-63 range.");
}
return _openPins.ContainsKey(pinNumber);
......@@ -136,7 +136,7 @@ namespace Iot.Device.Seesaw
{
if (pinNumber < 0 || pinNumber > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pinNumber), "Gpio pin must be within 0-63 range.");
}
if (IsPinOpen(pinNumber))
......@@ -157,7 +157,7 @@ namespace Iot.Device.Seesaw
{
if (pinNumber < 0 || pinNumber > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pinNumber), "Gpio pin must be within 0-63 range.");
}
if (!IsPinOpen(pinNumber))
......@@ -189,7 +189,7 @@ namespace Iot.Device.Seesaw
{
if (pinNumber < 0 || pinNumber > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pinNumber), "Gpio pin must be within 0-63 range.");
}
if (!_openPins.ContainsKey(pinNumber))
......@@ -210,7 +210,7 @@ namespace Iot.Device.Seesaw
{
if (pinNumber < 0 || pinNumber > 63)
{
throw new ArgumentOutOfRangeException("Gpio pin must be within 0-63 range.");
throw new ArgumentOutOfRangeException(nameof(pinNumber), "Gpio pin must be within 0-63 range.");
}
if (!IsPinOpen(pinNumber))
......
......@@ -40,7 +40,7 @@ namespace Iot.Device.SenseHat
{
if (colors.Length != NumberOfPixels)
{
throw new ArgumentException(nameof(colors), $"Value must be {NumberOfPixels} elements. Length: {nameof(colors)}.");
throw new ArgumentException($"Value must be {NumberOfPixels} elements. Length: {nameof(colors)}.", nameof(colors));
}
Span<byte> buffer = stackalloc byte[FrameBufferLength + 1];
......
......@@ -57,7 +57,7 @@ namespace Iot.Device.SenseHat
{
if (colors.Length != NumberOfPixels)
{
throw new ArgumentException(nameof(colors), $"Value must be {NumberOfPixels} elements. Length: {colors.Length}");
throw new ArgumentException($"Value must be {NumberOfPixels} elements. Length: {colors.Length}", nameof(colors));
}
StartWritingColors();
......
......@@ -39,12 +39,12 @@ namespace Iot.Device.SocketCan
{
if (!id.IsValid)
{
throw new ArgumentException(nameof(id), "Id is not valid. Ensure Error flag is not set and that id is in the valid range (11-bit for standard frame and 29-bit for extended frame).");
throw new ArgumentException("Id is not valid. Ensure Error flag is not set and that id is in the valid range (11-bit for standard frame and 29-bit for extended frame).", nameof(id));
}
if (data.Length > CanFrame.MaxLength)
{
throw new ArgumentException(nameof(data), $"Data length cannot exceed {CanFrame.MaxLength} bytes.");
throw new ArgumentException($"Data length cannot exceed {CanFrame.MaxLength} bytes.", nameof(data));
}
CanFrame frame = new CanFrame();
......@@ -73,7 +73,7 @@ namespace Iot.Device.SocketCan
{
if (data.Length < CanFrame.MaxLength)
{
throw new ArgumentException(nameof(data), $"Value must be a minimum of {CanFrame.MaxLength} bytes.");
throw new ArgumentException($"Value must be a minimum of {CanFrame.MaxLength} bytes.", nameof(data));
}
CanFrame frame = new CanFrame();
......@@ -125,7 +125,7 @@ namespace Iot.Device.SocketCan
{
if (!id.IsValid)
{
throw new ArgumentException(nameof(id), "Value must be a valid CanId");
throw new ArgumentException("Value must be a valid CanId", nameof(id));
}
Span<Interop.CanFilter> filters = stackalloc Interop.CanFilter[1];
......
......@@ -130,7 +130,7 @@ namespace Iot.Device.SocketCan
if (name.Length >= MaxLen)
{
throw new ArgumentException(nameof(name), $"Value exceeds maximum allowed length of {MaxLen} size.");
throw new ArgumentException($"Value exceeds maximum allowed length of {MaxLen} size.", nameof(name));
}
ifreq ifr = new ifreq();
......
......@@ -145,7 +145,7 @@ namespace Iot.Device.Spi
{
if (dataToWrite.Length != dataToRead.Length)
{
throw new ArgumentException(nameof(dataToWrite));
throw new ArgumentException($"{nameof(dataToWrite)} and {nameof(dataToWrite)} must have the same length.", nameof(dataToWrite));
}
if (_sdi == -1)
......
......@@ -45,13 +45,13 @@ namespace Iot.Device.Ssd1351
{
if (!InRange((uint)spiBufferSize, 0x1000, 0x10000))
{
throw new ArgumentException(nameof(spiBufferSize), "Value must be between 4096 and 65536.");
throw new ArgumentException("Value must be between 4096 and 65536.", nameof(spiBufferSize));
}
_gpioDevice = gpioController ?? new GpioController();
_shouldDispose = shouldDispose || gpioController is null;
_spiDevice = spiDevice ?? throw new ArgumentException(nameof(spiDevice));
_spiDevice = spiDevice ?? throw new ArgumentNullException(nameof(spiDevice));
_dcPinId = dataCommandPin;
_resetPinId = resetPin;
......
......@@ -44,7 +44,7 @@ namespace Iot.Device.Ssd1351
if (bm.PixelFormat != PixelFormat.Format32bppArgb)
{
throw new ArgumentException(nameof(bm), $"Pixel format {bm.PixelFormat.ToString()} not supported.");
throw new ArgumentException($"Pixel format {bm.PixelFormat.ToString()} not supported.", nameof(bm));
}
// get the pixel data and send it to the display
......@@ -70,7 +70,7 @@ namespace Iot.Device.Ssd1351
if (bm.PixelFormat != PixelFormat.Format32bppArgb)
{
throw new ArgumentException(nameof(bm), $"Pixel format {bm.PixelFormat.ToString()} not supported.");
throw new ArgumentException($"Pixel format {bm.PixelFormat.ToString()} not supported.", nameof(bm));
}
// allocate the working arrays.
......
......@@ -93,7 +93,7 @@ namespace Iot.Device.Ssd13xx
if (commandBytes is not { Length: >0 })
{
throw new ArgumentException(nameof(command), "Argument is either null or there were no bytes to send.");
throw new ArgumentException("Argument is either null or there were no bytes to send.", nameof(command));
}
foreach (var item in commandBytes)
......
......@@ -72,7 +72,7 @@ namespace Iot.Device.Tm1637
{
if (value.Length != MaxCharacters)
{
throw new ArgumentException(nameof(CharacterOrder), $"Value must be 6 bytes.");
throw new ArgumentException($"Value must be 6 bytes.", nameof(CharacterOrder));
}
// Check if we have all values from 0 to 5
......@@ -115,7 +115,7 @@ namespace Iot.Device.Tm1637
{
if (value > 7)
{
throw new ArgumentException(nameof(Brightness), "Value must be less than 8.");
throw new ArgumentException("Value must be less than 8.", nameof(Brightness));
}
_brightness = value;
......@@ -213,7 +213,7 @@ namespace Iot.Device.Tm1637
{
if (rawData.Length > MaxCharacters)
{
throw new ArgumentException(nameof(rawData), $"Maximum number of segments for TM1637 is {MaxCharacters}");
throw new ArgumentException($"Maximum number of segments for TM1637 is {MaxCharacters}", nameof(rawData));
}
// Prepare the buffer with the right order to transfer
......@@ -284,7 +284,7 @@ namespace Iot.Device.Tm1637
{
if (characterPosition > MaxCharacters)
{
throw new ArgumentException(nameof(characterPosition), $"Maximum number of characters for TM1637 is {MaxCharacters}");
throw new ArgumentException($"Maximum number of characters for TM1637 is {MaxCharacters}", nameof(characterPosition));
}
// Recreate the buffer in correct order
......
......@@ -47,7 +47,7 @@ namespace Iot.Device.Tsl256x
/// <param name="packageType">The type of package to have a proper illuminance calculation</param>
public Tsl256x(I2cDevice i2cDevice, PackageType packageType = PackageType.Other)
{
_i2cDevice = i2cDevice ?? throw new ArgumentNullException($"I2C Device can't be null");
_i2cDevice = i2cDevice ?? throw new ArgumentNullException(nameof(i2cDevice), $"I2C Device can't be null");
_packageType = packageType;
IntegrationTime = IntegrationTime.Integration402Milliseconds;
Gain = Gain.Normal;
......@@ -224,7 +224,7 @@ namespace Iot.Device.Tsl256x
break;
case IntegrationTime.Manual:
default:
throw new ArgumentOutOfRangeException($"Only non manual integration time are supported");
throw new InvalidOperationException($"Only non manual integration time are supported");
}
return GetIlluminance();
......
......@@ -59,7 +59,7 @@ namespace Iot.Device.UFire
/// </summary>
/// <param name="i2cDevice">The I2C device to be used</param>
public UFireIse(I2cDevice i2cDevice) =>
_device = i2cDevice ?? throw new ArgumentException(nameof(i2cDevice));
_device = i2cDevice ?? throw new ArgumentNullException(nameof(i2cDevice));
/// <summary>
/// Read a value from the ISE Probe Interface, typical measure are in the millivolt range.
......@@ -116,7 +116,7 @@ namespace Iot.Device.UFire
}
else
{
throw new ArgumentOutOfRangeException("The value range is -1024 mV to 1024 mV");
throw new ArgumentOutOfRangeException(nameof(solution), "The value range is -1024 mV to 1024 mV");
}
}
......@@ -135,7 +135,7 @@ namespace Iot.Device.UFire
}
else
{
throw new ArgumentOutOfRangeException("The value range is -1024 mV to 1024 mV");
throw new ArgumentOutOfRangeException(nameof(solution), "The value range is -1024 mV to 1024 mV");
}
}
......@@ -154,7 +154,7 @@ namespace Iot.Device.UFire
}
else
{
throw new ArgumentOutOfRangeException("The value range is -1024 mV to 1024 mV");
throw new ArgumentOutOfRangeException(nameof(solution), "The value range is -1024 mV to 1024 mV");
}
}
......@@ -230,7 +230,7 @@ namespace Iot.Device.UFire
}
else
{
throw new ArgumentOutOfRangeException("The value range is -1024 mV to 1024 mV for refLow, refHigh, readLow and readLow");
throw new ArgumentOutOfRangeException(nameof(refLow), "The value range is -1024 mV to 1024 mV for refLow, refHigh, readLow and readLow");
}
}
......@@ -247,7 +247,7 @@ namespace Iot.Device.UFire
}
else
{
throw new ArgumentOutOfRangeException("The value range is 1 to 127");
throw new ArgumentOutOfRangeException(nameof(i2cAddress), "The value range is 1 to 127");
}
Dispose();
......
......@@ -93,7 +93,7 @@ namespace Iot.Device.Vl53L0X
{
if (newAddress > 0x7F)
{
throw new ArgumentException(nameof(newAddress), "Value can't exceed 0x7F");
throw new ArgumentException("Value can't exceed 0x7F", nameof(newAddress));
}
try
......@@ -1129,7 +1129,7 @@ namespace Iot.Device.Vl53L0X
{
if ((limitMcps < 0) || (limitMcps > 511.99))
{
throw new ArgumentException(nameof(limitMcps), "Value can't be negative or greater than 511.99");
throw new ArgumentException("Value can't be negative or greater than 511.99", nameof(limitMcps));
}
// Q9.7 fixed point format (9 integer bits, 7 fractional bits)
......
......@@ -170,7 +170,7 @@ namespace GenerateDocFxStructure
{
if ((_options == null) || (_message == null))
{
throw new ArgumentNullException($"Options or message can't be null, something went wrong");
throw new InvalidOperationException($"Options or message can't be null, something went wrong");
}
string[] lines = File.ReadAllLines(filepath);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册