संपादित करें

इसके माध्यम से साझा किया गया


Contract.EnsuresOnThrow Method

Definition

Specifies a postcondition contract for the enclosing method or property based on the provided exception and condition.

Overloads

EnsuresOnThrow<TException>(Boolean)

Specifies a postcondition contract for the enclosing method or property, based on the provided exception and condition.

EnsuresOnThrow<TException>(Boolean, String)

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.

EnsuresOnThrow<TException>(Boolean)

Source:
Contracts.cs
Source:
Contracts.cs
Source:
Contracts.cs

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);
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void EnsuresOnThrow<TException> (bool condition) where TException : 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)

Type Parameters

TException

The type of exception that invokes the postcondition check.

Parameters

condition
Boolean

The conditional expression to test.

Attributes

Remarks

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.

Applies to

EnsuresOnThrow<TException>(Boolean, String)

Source:
Contracts.cs
Source:
Contracts.cs
Source:
Contracts.cs

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);
[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;
[<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)

Type Parameters

TException

The type of exception that invokes the postcondition check.

Parameters

condition
Boolean

The conditional expression to test.

userMessage
String

The message to display if the expression is false.

Attributes

Remarks

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. 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.

  • If userMessage is not a constant string literal, the contract may not be understood by tools.

Applies to