Add and use ArgumentOutOfRangeException.ThrowIfNegativeOrZero
このコミットが含まれているのは:
1 親
ee6002bbdb
コミット
98fb8e68ce
2ファイル変更
+22
-6
検索条件に一致するファイルはありません
@@ -19,7 +19,22 @@ internal static class ArgumentOutOfRangeExceptionExtensions
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
Throw(parameterName);
|
||||
Throw(parameterName, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is negative or zero.
|
||||
/// </summary>
|
||||
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
|
||||
/// <param name="value">The argument to validate as non-zero or non-negative.</param>
|
||||
/// <param name="parameterName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ThrowIfNegativeOrZero(this ArgumentOutOfRangeException? _, int value, [CallerArgumentExpression(nameof(value))] string? parameterName = null)
|
||||
{
|
||||
if (value <= 0)
|
||||
{
|
||||
Throw(parameterName, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +42,11 @@ internal static class ArgumentOutOfRangeExceptionExtensions
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> for a given parameter name.
|
||||
/// </summary>
|
||||
/// <param name="parameterName">The name of the parameter to report in the exception.</param>
|
||||
/// <param name="value">The invalid value that was used.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with <paramref name="parameterName"/>.</exception>
|
||||
[DoesNotReturn]
|
||||
private static void Throw(string? parameterName)
|
||||
private static void Throw(string? parameterName, int value)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(parameterName);
|
||||
throw new ArgumentOutOfRangeException(parameterName, value, null);
|
||||
}
|
||||
}
|
||||
@@ -181,9 +181,9 @@ public struct ComputeContext : IDisposable, IAsyncDisposable
|
||||
{
|
||||
ThrowInvalidOperationExceptionIfDeviceIsNull();
|
||||
|
||||
Guard.IsGreaterThan(x, 0);
|
||||
Guard.IsGreaterThan(y, 0);
|
||||
Guard.IsGreaterThan(z, 0);
|
||||
default(ArgumentOutOfRangeException).ThrowIfNegativeOrZero(x);
|
||||
default(ArgumentOutOfRangeException).ThrowIfNegativeOrZero(y);
|
||||
default(ArgumentOutOfRangeException).ThrowIfNegativeOrZero(z);
|
||||
Guard.IsBetweenOrEqualTo(threadsX, 1, 1024);
|
||||
Guard.IsBetweenOrEqualTo(threadsY, 1, 1024);
|
||||
Guard.IsBetweenOrEqualTo(threadsZ, 1, 64);
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする