<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />

System.ComponentModel.DataAnnotations.ValidationAttribute

public abstract class ValidationAttribute : Attribute
Serves as the base class for all validation attributes.
public string ErrorMessage { get; set; }

Gets or sets an error message to associate with a validation control if validation fails.

public string ErrorMessageResourceName { get; set; }

Gets or sets the error message resource name to use in order to look up the ErrorMessageResourceType property value if validation fails.

public Type ErrorMessageResourceType { get; set; }

Gets or sets the resource type to use for error-message lookup if validation fails.

protected string ErrorMessageString { get; }

Gets the localized validation error message.

public virtual bool RequiresValidationContext { get; }

Gets a value that indicates whether the attribute requires validation context.

protected ValidationAttribute()

Initializes a new instance of the ValidationAttribute class.

protected ValidationAttribute(string errorMessage)

Initializes a new instance of the ValidationAttribute class by using the error message to associate with a validation control.

protected ValidationAttribute(Func<string> errorMessageAccessor)

Initializes a new instance of the ValidationAttribute class by using the function that enables access to validation resources.

public virtual string FormatErrorMessage(string name)

Applies formatting to an error message, based on the data field where the error occurred.

public ValidationResult GetValidationResult(object value, ValidationContext validationContext)

Checks whether the specified value is valid with respect to the current validation attribute.

public virtual bool IsValid(object value)

Determines whether the specified value of the object is valid.

protected virtual ValidationResult IsValid(object value, ValidationContext validationContext)

Validates the specified value with respect to the current validation attribute.

public void Validate(object value, string name)

Validates the specified object.

public void Validate(object value, ValidationContext validationContext)

Validates the specified object.