共用方式為


CustomValidationAttribute.Method 屬性

定義

取得驗證方法。

public:
 property System::String ^ Method { System::String ^ get(); };
public string Method { get; }
member this.Method : string
Public ReadOnly Property Method As String

屬性值

驗證方法的名稱。

備註

此屬性所指定的自訂方法必須是公開且靜態的,且必須回傳一個布林值。 同時也必須至少有一個輸入參數指定要驗證的物件。 此參數可被強型別化。 若程序傳遞不同類型的值,則會嘗試型別轉換。

若指定物件有效,該方法應回傳 true 。 否則,它應該會傳回 false

自訂方法也可以接受參數來指定 ValidationContext 輸入值與 ValidationResult 輸出值。 參數 ValidationContext 提供額外的上下文資訊,方法可用來判斷其所處的上下文。 ValidationResult輸出參數使方法能夠回傳錯誤訊息。

若方法回傳nullValidationResult參數或回傳為空ErrorMessage值,則會呼叫預設FormatErrorMessage方法來組合錯誤訊息。

適用於