ASP.NET CORE基础教程

  public abstract class ValidationAttribute : Attribute

  {

  ///

Initializes a new instance of the class.

  protected ValidationAttribute();

  ///

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

  /// The function that enables access to validation resources.

  /// errorMessageAccessor is null.

  protected ValidationAttribute(Func errorMessageAccessor);

  ///

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

  /// The error message to associate with a validation control.

  protected ValidationAttribute(string errorMessage);

  ///

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

  /// The error message that is associated with the validation control.

  public string ErrorMessage { get; set; }

  ///

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

  /// The error message resource that is associated with a validation control.

  public string ErrorMessageResourceName { get; set; }

  ///

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

  /// The type of error message that is associated with a validation control.

  public Type ErrorMessageResourceType { get; set; }

  ///

Gets the localized validation error message.

  /// The localized validation error message.

  protected string ErrorMessageString { get; }

  ///

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

  /// true if the attribute requires validation context; otherwise, false.

  public virtual bool RequiresValidationContext { get; }

  ///

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

  /// The name to include in the formatted message.

  /// An instance of the formatted error message.

  public virtual string FormatErrorMessage(string name);

  ///

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

  /// The value to validate.

  /// The context information about the validation operation.

  /// An instance of the class.

  public ValidationResult GetValidationResult(

  object value,

  ValidationContext validationContext);

  ///

Determines whether the specified value of the object is valid.

  /// The value of the object to validate.

  /// true if the specified value is valid; otherwise, false.

  public virtual bool IsValid(object value);

  ///

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

  /// The value to validate.

  /// The context information about the validation operation.

  /// An instance of the class.

  protected virtual ValidationResult IsValid(

  object value,

  ValidationContext validationContext);

  ///

Validates the specified object.

  /// The object to validate.

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

  /// Validation failed.

  public void Validate(object value, ValidationContext validationContext);

  ///

Validates the specified object.

  /// The value of the object to validate.

  /// The name to include in the error message.

  /// value is not valid.

  public void Validate(object value, string name);

  }