ValidationAttribute.Validate 方法

定义

验证指定的对象。Validates the specified object.

重载

Validate(Object, ValidationContext)

验证指定的对象。Validates the specified object.

Validate(Object, String)

验证指定的对象。Validates the specified object.

Validate(Object, ValidationContext)

验证指定的对象。Validates the specified object.

public:
 void Validate(System::Object ^ value, System::ComponentModel::DataAnnotations::ValidationContext ^ validationContext);
public void Validate (object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext);
public void Validate (object? value, System.ComponentModel.DataAnnotations.ValidationContext validationContext);
member this.Validate : obj * System.ComponentModel.DataAnnotations.ValidationContext -> unit
Public Sub Validate (value As Object, validationContext As ValidationContext)

参数

value
Object

要验证的对象。The object to validate.

validationContext
ValidationContext

描述验证检查的执行上下文的 ValidationContext 对象。The ValidationContext object that describes the context where the validation checks are performed. 此参数不能为 nullThis parameter cannot be null.

例外

验证失败。Validation failed.

当前属性格式错误。The current attribute is malformed.

派生类尚未实现 IsValid(Object, ValidationContext)IsValid(Object, ValidationContext) has not been implemented by a derived class.

注解

此方法调用 IsValid 方法来确定参数指定的对象是否 value 有效。This method calls the IsValid method to determine whether the object that is specified by the value parameter is valid. 如果该 IsValid 方法返回 false ,则此方法将调用 FormatErrorMessage 方法来获取说明该问题的本地化消息。If the IsValid method returns false, this method calls the FormatErrorMessage method to get a localized message that states the problem. 然后,它会引发 ValidationException 异常。It then throws a ValidationException exception.

适用于

Validate(Object, String)

验证指定的对象。Validates the specified object.

public:
 void Validate(System::Object ^ value, System::String ^ name);
public void Validate (object value, string name);
public void Validate (object? value, string name);
member this.Validate : obj * string -> unit
Public Sub Validate (value As Object, name As String)

参数

value
Object

要验证的对象的值。The value of the object to validate.

name
String

要包括在错误消息中的名称。The name to include in the error message.

例外

value 无效。value is not valid.

当前属性格式错误。The current attribute is malformed.

注解

此方法验证要在其上声明属性的对象或属性的值 ValidationAttributeThis method validates the value of the object or property on which the ValidationAttribute attribute is declared. 它调用 IsValid 方法并将 value 作为参数传递。It calls the IsValid method and passes value as a parameter. 如果验证失败,则 ValidationException 会引发异常。If validation fails, a ValidationException exception is thrown.

适用于