Contract.Assert 方法

定義

在偵錯組建中,為指定的條件進行執行階段測試。In debug builds, performs a run-time test for a specified condition.

多載

Assert(Boolean)

檢查條件,且如果條件為 false,則遵循已為分析器設定的擴大原則。Checks for a condition; if the condition is false, follows the escalation policy set for the analyzer.

Assert(Boolean, String)

檢查條件。如果條件為 false,則遵循分析器所設定的擴大原則,並顯示指定的訊息。Checks for a condition; if the condition is false, follows the escalation policy set by the analyzer and displays the specified message.

Assert(Boolean)

檢查條件,且如果條件為 false,則遵循已為分析器設定的擴大原則。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)

參數

condition
Boolean

要測試的條件運算式。The conditional expression to test.

屬性

備註

預設的擴大原則是通知附加的偵錯工具有關合約失敗,或如果未附加偵錯工具, 則顯示 [判斷提示] 對話方塊。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)

檢查條件。如果條件為 false,則遵循分析器所設定的擴大原則,並顯示指定的訊息。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)

參數

condition
Boolean

要測試的條件運算式。The conditional expression to test.

userMessage
String

當條件不符合時所顯示的訊息。A message to display if the condition is not met.

屬性

備註

預設的擴大原則是通知附加的偵錯工具有關合約失敗,或如果未附加偵錯工具, 則顯示 [判斷提示] 對話方塊。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. userMessage 參數會傳遞至偵錯工具輸出。The userMessage parameter is passed to the debugger output. 如果 userMessage 不是常數位符串常值,則工具可能無法讀取它。If userMessage is not a constant string literal, tools may not be able to read it.

適用於