Επεξεργασία

Κοινή χρήση μέσω


ValidationAttribute.Validate Method

Definition

Validates the specified object.

Overloads

Validate(Object, ValidationContext)

Validates the specified object.

Validate(Object, String)

Validates the specified object.

Validate(Object, ValidationContext)

Source:
ValidationAttribute.cs
Source:
ValidationAttribute.cs
Source:
ValidationAttribute.cs

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)

Parameters

value
Object

The object to validate.

validationContext
ValidationContext

The ValidationContext object that describes the context where the validation checks are performed. This parameter cannot be null.

Exceptions

Validation failed.

The current attribute is malformed.

IsValid(Object, ValidationContext) has not been implemented by a derived class.

Remarks

This method calls the IsValid method to determine whether the object that is specified by the value parameter is valid. If the IsValid method returns false, this method calls the FormatErrorMessage method to get a localized message that states the problem. It then throws a ValidationException exception.

Applies to

Validate(Object, String)

Source:
ValidationAttribute.cs
Source:
ValidationAttribute.cs
Source:
ValidationAttribute.cs

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)

Parameters

value
Object

The value of the object to validate.

name
String

The name to include in the error message.

Exceptions

value is not valid.

The current attribute is malformed.

Remarks

This method validates the value of the object or property on which the ValidationAttribute attribute is declared. It calls the IsValid method and passes value as a parameter. If validation fails, a ValidationException exception is thrown.

Applies to