Add and use ArgumentOutOfRangeException.ThrowIfGreaterThan

このコミットが含まれているのは:
Sergio Pedri committed 2023-02-25 17:00:29 +01:00
1 親 cd19e8cdc1
コミット b00fc5d9d4
7ファイル変更
+64 -51

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

+15
ファイルの表示
@@ -38,6 +38,21 @@ internal static class ArgumentOutOfRangeExceptionExtensions
}
}
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is greater than <paramref name="other"/>.
/// </summary>
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
/// <param name="value">The argument to validate as less or equal than <paramref name="other"/>.</param>
/// <param name="other">The value to compare with <paramref name="value"/>.</param>
/// <param name="parameterName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
public static void ThrowIfGreaterThan(this ArgumentOutOfRangeException? _, int value, int other, [CallerArgumentExpression(nameof(value))] string? parameterName = null)
{
if (value > other)
{
Throw(parameterName, value);
}
}
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is not in the specified range.
/// </summary>