System.Diagnostics.Contracts.Contract.Assert Method

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

Syntax

[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
[System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)]
public static void Assert (bool condition, string userMessage)

Parameters

condition
The conditional expression to test.
userMessage
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.

Requirements

Namespace: System.Diagnostics.Contracts
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 4.0.0.0