通过


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 参数使该方法能够返回错误消息。

如果方法 null 返回 ValidationResult 参数或返回属性的 ErrorMessage 空值,将调用默认 FormatErrorMessage 方法以撰写错误消息。

适用于