Contract.EndContractBlock 方法

定義

當方法的合約僅包含 if-then-throw 形式的前置條件時,標記合約區段的結尾。Marks the end of the contract section when a method's contracts contain only preconditions in the if-then-throw form.

public:
 static void EndContractBlock();
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void EndContractBlock ();
static member EndContractBlock : unit -> unit
Public Shared Sub EndContractBlock ()
屬性

備註

大部分的程式碼都已經包含 if-then-throw 程式碼形式的一些參數驗證。Most code already contains some parameter validation in the form of if-then-throw code. 當語句第一次出現在方法內,而且整個這類語句後面接著明確的 throw 方法呼叫(例如 ContractRequiresEnsuresEnsuresOnThrow)時,合約工具會辨識 if-then-EndContractBlock語句做為前置條件。The contract tools recognize if-then-throw statements as preconditions when the statements appear first inside a method, and the entire set of such statements is followed by an explicit Contract method call, such as a Requires, Ensures, EnsuresOnThrow, or EndContractBlock.

if-then-throw 語句以這種形式出現時,合約工具會將它們辨識為舊版-需要語句。When if-then-throw statements appear in this form, the contract tools recognize them as legacy-require statements. 只有在沒有其他合約遵循 if-then-throw 序列時,才會使用 EndContractBlock 表單,但仍應將其標記為舊版-需要。The EndContractBlock form is used only if no other contracts follow the if-then-throw sequences, but they should still be tagged as legacy-requires.

適用於