Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​ComponentModel.​DataAnnotations.​Validator

Assembly: System.ComponentModel.Annotations

Inheritance: object → Validator

Defines a helper class that can be used to validate objects, properties, and methods when it is included in their associated <see cref="T:System.ComponentModel.DataAnnotations.ValidationAttribute" /> attributes.

Methods

public static bool
TryValidateObject​(object instance, ValidationContext validationContext, Collections.​Generic.​ICollection?<​ValidationResult> validationResults)
Determines whether the specified object is valid using the validation context and validation results collection.
Returns <see langword="true" /> if the object validates; otherwise, <see langword="false" /> .
instance The object to validate.
validationContext The context that describes the object to validate.
validationResults A collection to hold each failed validation.
public static bool
TryValidateObject​(object instance, ValidationContext validationContext, Collections.​Generic.​ICollection?<​ValidationResult> validationResults, bool validateAllProperties)
Determines whether the specified object is valid using the validation context, validation results collection, and a value that specifies whether to validate all properties.
Returns <see langword="true" /> if the object validates; otherwise, <see langword="false" /> .
instance The object to validate.
validationContext The context that describes the object to validate.
validationResults A collection to hold each failed validation.
validateAllProperties <see langword="true" /> to validate all properties; if <see langword="false" /> , only required attributes are validated.
public static bool
TryValidateProperty​(object value, ValidationContext validationContext, Collections.​Generic.​ICollection?<​ValidationResult> validationResults)
Validates the property.
Returns <see langword="true" /> if the property validates; otherwise, <see langword="false" /> .
value The value to validate.
validationContext The context that describes the property to validate.
validationResults A collection to hold each failed validation.
public static bool
TryValidateValue​(object value, ValidationContext validationContext, Collections.​Generic.​ICollection?<​ValidationResult> validationResults, Collections.​Generic.​IEnumerable<​ValidationAttribute> validationAttributes)
Returns a value that indicates whether the specified value is valid with the specified attributes.
Returns <see langword="true" /> if the object validates; otherwise, <see langword="false" /> .
value The value to validate.
validationContext The context that describes the object to validate.
validationResults A collection to hold failed validations.
validationAttributes The validation attributes.
public static void
ValidateObject​(object instance, ValidationContext validationContext)
Determines whether the specified object is valid using the validation context.
instance The object to validate.
validationContext The context that describes the object to validate.
public static void
ValidateObject​(object instance, ValidationContext validationContext, bool validateAllProperties)
Determines whether the specified object is valid using the validation context, and a value that specifies whether to validate all properties.
instance The object to validate.
validationContext The context that describes the object to validate.
validateAllProperties <see langword="true" /> to validate all properties; otherwise, <see langword="false" /> .
public static void
ValidateProperty​(object value, ValidationContext validationContext)
Validates the property.
value The value to validate.
validationContext The context that describes the property to validate.
public static void
ValidateValue​(object value, ValidationContext validationContext, Collections.​Generic.​IEnumerable<​ValidationAttribute> validationAttributes)
Validates the specified attributes.
value The value to validate.
validationContext The context that describes the object to validate.
validationAttributes The validation attributes.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object