Επεξεργασία

Κοινή χρήση μέσω


Contract.Assert Method

Definition

In debug builds, performs a run-time test for a specified condition.

Overloads

Assert(Boolean)

Checks for a condition; if the condition is false, follows the escalation policy set for the analyzer.

Assert(Boolean, String)

Checks for a condition; if the condition is false, follows the escalation policy set by the analyzer and displays the specified message.

Assert(Boolean)

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

Checks for a condition; if the condition is false, follows the escalation policy set for the analyzer.

public:
 static void Assert(bool condition);
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
[System.Diagnostics.Conditional("DEBUG")]
public static void Assert (bool condition);
[<System.Diagnostics.Conditional("CONTRACTS_FULL")>]
[<System.Diagnostics.Conditional("DEBUG")>]
static member Assert : bool -> unit
Public Shared Sub Assert (condition As Boolean)

Parameters

condition
Boolean

The conditional expression to test.

Attributes

Remarks

The default escalation policy is to notify the attached debugger about a contract failure or to display an Assert dialog box if a debugger is not attached. Optionally, the analyzer can be instructed to throw an exception.

Applies to

Assert(Boolean, String)

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

Checks for a condition; if the condition is false, follows the escalation policy set by the analyzer and displays the specified message.

public:
 static void Assert(bool condition, System::String ^ userMessage);
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assert (bool condition, string userMessage);
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assert (bool condition, string? userMessage);
[<System.Diagnostics.Conditional("DEBUG")>]
[<System.Diagnostics.Conditional("CONTRACTS_FULL")>]
static member Assert : bool * string -> unit
Public Shared Sub Assert (condition As Boolean, userMessage As String)

Parameters

condition
Boolean

The conditional expression to test.

userMessage
String

A message to display if the condition is not met.

Attributes

Remarks

The default escalation policy is to notify the attached debugger about a contract failure or to display an Assert dialog box if a debugger is not attached. Optionally, the analyzer can be instructed to throw an exception. The userMessage parameter is passed to the debugger output. If userMessage is not a constant string literal, tools may not be able to read it.

Applies to