Contract.Assume 方法

定義

指示程式碼分析工具假設條件為 true,即使該條件無法以靜態方式證明永遠是 true 亦然。Instructs code analysis tools to assume that a condition is true, even if it cannot be statically proven to always be true.

多載

Assume(Boolean)

指示程式碼分析工具假設指定的條件為 true,即使該條件無法以靜態方式證明永遠是 true 亦然。Instructs code analysis tools to assume that the specified condition is true, even if it cannot be statically proven to always be true.

Assume(Boolean, String)

指示程式碼分析工具假設條件為 true,即使該條件無法以靜態方式證明永遠是 true 亦然,同時在假設失敗時顯示訊息。Instructs code analysis tools to assume that a condition is true, even if it cannot be statically proven to always be true, and displays a message if the assumption fails.

Assume(Boolean)

指示程式碼分析工具假設指定的條件為 true,即使該條件無法以靜態方式證明永遠是 true 亦然。Instructs code analysis tools to assume that the specified condition is true, even if it cannot be statically proven to always be true.

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

參數

condition
Boolean

要假設 true 的條件運算式。The conditional expression to assume true.

屬性

備註

在執行時間,使用這個方法相當於使用 Assert(Boolean) 方法。At run time, using this method is equivalent to using the Assert(Boolean) method.

Assume(Boolean, String)

指示程式碼分析工具假設條件為 true,即使該條件無法以靜態方式證明永遠是 true 亦然,同時在假設失敗時顯示訊息。Instructs code analysis tools to assume that a condition is true, even if it cannot be statically proven to always be true, and displays a message if the assumption fails.

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

參數

condition
Boolean

要假設 true 的條件運算式。The conditional expression to assume true.

userMessage
String

要在假設失敗時張貼的訊息。The message to post if the assumption fails.

屬性

備註

如果 userMessage 不是常數位串常值,則工具可能無法理解合約。If userMessage is not a constant string literal, the contract may not be understood by tools.

在執行時間,使用這個方法相當於使用 Assert(Boolean, String) 方法。At run time, using this method is equivalent to using the Assert(Boolean, String) method.

適用於