Contract.Assert Contract.Assert Contract.Assert Contract.Assert Method

Definition

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

Overloads

Assert(Boolean) Assert(Boolean) Assert(Boolean) Assert(Boolean)

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

Assert(Boolean, String) Assert(Boolean, String) Assert(Boolean, String) 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) Assert(Boolean) Assert(Boolean) Assert(Boolean)

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);
static member Assert : bool -> unit
Public Shared Sub Assert (condition As Boolean)
Parameters
condition
Boolean Boolean Boolean Boolean

The conditional expression to test.

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.

Assert(Boolean, String) Assert(Boolean, String) Assert(Boolean, String) 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.

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

The conditional expression to test.

userMessage
String String String String

A message to display if the condition is not met.

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