Add and use ArgumentOutOfRangeExceptionExtensions.ThrowIfNotZero

このコミットが含まれているのは:
Sergio Pedri committed 2023-02-25 17:22:38 +01:00
1 親 1c6f144064
コミット e4c7b5161c
3ファイル変更
+16 -4

検索条件に一致するファイルはありません

+14
ファイルの表示
@@ -8,6 +8,20 @@ namespace System;
/// </summary>
internal static class ArgumentOutOfRangeExceptionExtensions
{
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is not 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 zero.</param>
/// <param name="parameterName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
public static void ThrowIfNotZero(this ArgumentOutOfRangeException? _, int value, [CallerArgumentExpression(nameof(value))] string? parameterName = null)
{
if (value != 0)
{
Throw(parameterName, value);
}
}
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is negative.
/// </summary>