Contract.EnsuresOnThrow メソッド
定義
指定された例外および条件に基づいて、外側のメソッドまたはプロパティに実行後の状態のコントラクトを指定します。Specifies a postcondition contract for the enclosing method or property based on the provided exception and condition.
オーバーロード
EnsuresOnThrow<TException>(Boolean) |
指定された例外および条件に基づいて、外側のメソッドまたはプロパティに実行後の状態のコントラクトを指定します。Specifies a postcondition contract for the enclosing method or property, based on the provided exception and condition. |
EnsuresOnThrow<TException>(Boolean, String) |
指定された例外および条件に基づいて、実行後の状態のコントラクトと、外側のメソッドまたはプロパティの条件が |
EnsuresOnThrow<TException>(Boolean)
指定された例外および条件に基づいて、外側のメソッドまたはプロパティに実行後の状態のコントラクトを指定します。Specifies a postcondition contract for the enclosing method or property, based on the provided exception and condition.
public:
generic <typename TException>
where TException : Exception static void EnsuresOnThrow(bool condition);
public static void EnsuresOnThrow<TException> (bool condition) where TException : Exception;
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void EnsuresOnThrow<TException> (bool condition) where TException : Exception;
static member EnsuresOnThrow : bool -> unit (requires 'Exception :> Exception)
[<System.Diagnostics.Conditional("CONTRACTS_FULL")>]
static member EnsuresOnThrow : bool -> unit (requires 'Exception :> Exception)
Public Shared Sub EnsuresOnThrow(Of TException As Exception) (condition As Boolean)
型パラメーター
- TException
実行後の状態のチェックを起動する例外の種類。The type of exception that invokes the postcondition check.
パラメーター
- condition
- Boolean
テストする条件式。The conditional expression to test.
- 属性
注釈
この condition
パラメーターは、 true
外側のメソッドまたはプロパティが異常終了し、型の例外がスローされた場合に想定される事後条件を指定し TException
ます。The condition
parameter specifies a postcondition that is expected to be true
when the enclosing method or property terminates abnormally and an exception of type TException
is thrown.
このメソッドの呼び出しは、他のコードの前にあるメソッドまたはプロパティの先頭にある必要があります。This method call must be at the beginning of a method or property, before any other code.
このコントラクトはクライアントに公開されます。したがって、少なくとも外側のメソッドとして表示されるメンバーのみを参照する必要があります。This contract is exposed to clients; therefore, it must only reference members that are at least as visible as the enclosing method.
この事後条件の実行時の強制には、バイナリリライターを使用する必要があります。You must use the binary rewriter for run-time enforcement of this postcondition.
適用対象
EnsuresOnThrow<TException>(Boolean, String)
指定された例外および条件に基づいて、実行後の状態のコントラクトと、外側のメソッドまたはプロパティの条件が false
の場合に表示するメッセージを指定します。Specifies a postcondition contract and a message to display if the condition is false
for the enclosing method or property, based on the provided exception and condition.
public:
generic <typename TException>
where TException : Exception static void EnsuresOnThrow(bool condition, System::String ^ userMessage);
public static void EnsuresOnThrow<TException> (bool condition, string userMessage) where TException : Exception;
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void EnsuresOnThrow<TException> (bool condition, string? userMessage) where TException : Exception;
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void EnsuresOnThrow<TException> (bool condition, string userMessage) where TException : Exception;
static member EnsuresOnThrow : bool * string -> unit (requires 'Exception :> Exception)
[<System.Diagnostics.Conditional("CONTRACTS_FULL")>]
static member EnsuresOnThrow : bool * string -> unit (requires 'Exception :> Exception)
Public Shared Sub EnsuresOnThrow(Of TException As Exception) (condition As Boolean, userMessage As String)
型パラメーター
- TException
実行後の状態のチェックを起動する例外の種類。The type of exception that invokes the postcondition check.
パラメーター
- condition
- Boolean
テストする条件式。The conditional expression to test.
- userMessage
- String
式が false
の場合に表示するメッセージ。The message to display if the expression is false
.
- 属性
注釈
この condition
パラメーターは、 true
外側のメソッドまたはプロパティが異常終了し、型の例外がスローされた場合に想定される事後条件を指定し TException
ます。The condition
parameter specifies a postcondition that is expected to be true
when the enclosing method or property terminates abnormally and an exception of type TException
is thrown. パラメーターは、 message
条件がの場合に表示するメッセージを指定し false
ます。The message
parameter specifies a message to display if the condition is false
.
このメソッドの呼び出しは、他のコードの前にあるメソッドまたはプロパティの先頭にある必要があります。This method call must be at the beginning of a method or property, before any other code.
このコントラクトはクライアントに公開されます。したがって、少なくとも外側のメソッドとして表示されるメンバーのみを参照する必要があります。This contract is exposed to clients; therefore, it must only reference members that are at least as visible as the enclosing method.
この事後条件の実行時の強制には、バイナリリライターを使用する必要があります。You must use the binary rewriter for run-time enforcement of this postcondition.
userMessage
が定数文字列リテラルでない場合は、ツールによってコントラクトが認識されない可能性があります。IfuserMessage
is not a constant string literal, the contract may not be understood by tools.