ValidationAttribute.Validate Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Validates the specified object.
Validate(Object, ValidationContext) |
Validates the specified object. |
Validate(Object, String) |
Validates the specified object. |
- 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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 (package-provided) |
UWP | 10.0 |
- 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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 (package-provided) |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: