Add and use InvalidOperationExceptionExtensions.ThrowIf
このコミットが含まれているのは:
1 親
e4c7b5161c
コミット
e27fb13a01
6ファイル変更
+51
-55
検索条件に一致するファイルはありません
@@ -15,7 +15,7 @@ internal static class ArgumentExceptionExtensions
|
||||
/// <param name="condition">The condition to decide whether to throw the exception.</param>
|
||||
/// <param name="parameterName">The name of the parameter with which <paramref name="condition"/> corresponds.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ThrowIf(this ArgumentException? _, bool condition, string? parameterName = null)
|
||||
public static void ThrowIf(this ArgumentException? _, [DoesNotReturnIf(true)] bool condition, string? parameterName = null)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System;
|
||||
|
||||
/// <summary>
|
||||
/// Throw helper extensions for <see cref="InvalidOperationException"/>.
|
||||
/// </summary>
|
||||
internal static class InvalidOperationExceptionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="InvalidOperationException"/> if <paramref name="condition"/> is <see langword="true"/>.
|
||||
/// </summary>
|
||||
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
|
||||
/// <param name="condition">The condition to decide whether to throw the exception.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ThrowIf(this InvalidOperationException? _, [DoesNotReturnIf(true)] bool condition)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
Throw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="InvalidOperationException"/> for a given parameter name.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Always thrown with no parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
private static void Throw()
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする