ValidationAttribute.IsValid 方法

定义

检查指定的对象是否有效。Checks whether the specified object is valid.

重载

IsValid(Object)

确定对象的指定值是否有效。Determines whether the specified value of the object is valid.

IsValid(Object, ValidationContext)

根据当前的验证特性来验证指定的值。Validates the specified value with respect to the current validation attribute.

IsValid(Object)

确定对象的指定值是否有效。Determines whether the specified value of the object is valid.

public:
 virtual bool IsValid(System::Object ^ value);
public:
 abstract bool IsValid(System::Object ^ value);
public virtual bool IsValid (object value);
public virtual bool IsValid (object? value);
public abstract bool IsValid (object value);
abstract member IsValid : obj -> bool
override this.IsValid : obj -> bool
abstract member IsValid : obj -> bool
Public Overridable Function IsValid (value As Object) As Boolean
Public MustOverride Function IsValid (value As Object) As Boolean

参数

value
Object

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

返回

Boolean

如果指定的值有效,则为 true;否则,为 falsetrue if the specified value is valid; otherwise, false.

例外

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

派生类尚未实现 IsValid 的任何重载。Neither overload of IsValid has been implemented by a derived class.

注解

如果从 ValidationAttribute 类继承,则必须在此方法中实现验证逻辑。If you inherit from the ValidationAttribute class, you must implement the validation logic in this method.

适用于

IsValid(Object, ValidationContext)

根据当前的验证特性来验证指定的值。Validates the specified value with respect to the current validation attribute.

protected:
 virtual System::ComponentModel::DataAnnotations::ValidationResult ^ IsValid(System::Object ^ value, System::ComponentModel::DataAnnotations::ValidationContext ^ validationContext);
protected virtual System.ComponentModel.DataAnnotations.ValidationResult IsValid (object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext);
protected virtual System.ComponentModel.DataAnnotations.ValidationResult? IsValid (object? value, System.ComponentModel.DataAnnotations.ValidationContext validationContext);
abstract member IsValid : obj * System.ComponentModel.DataAnnotations.ValidationContext -> System.ComponentModel.DataAnnotations.ValidationResult
override this.IsValid : obj * System.ComponentModel.DataAnnotations.ValidationContext -> System.ComponentModel.DataAnnotations.ValidationResult
Protected Overridable Function IsValid (value As Object, validationContext As ValidationContext) As ValidationResult

参数

value
Object

要验证的值。The value to validate.

validationContext
ValidationContext

有关验证操作的上下文信息。The context information about the validation operation.

返回

ValidationResult

ValidationResult 类的实例。An instance of the ValidationResult class.

例外

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

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

另请参阅

适用于