Class DataAnnotationValidator
Implements methods to validate property values based on their data annotations.
Namespace: Sartorius.SAF.Validation
Assembly: Sartorius.SAF.dll
Syntax
public static class DataAnnotationValidator
Examples
All examples validate the following class.
This example illustrates how to the Validate(object) method to validate all properties of the given instance and get a list of IError as result. This method is obsolete.
This example illustrates how to use the Validate<TInstance>(TInstance) method to validate all properties of the given instance and get a list of ValidationResult as result.
This example illustrates how to use the Validate<TValue>(Expression<Func<TValue>>, TValue) method to validate the given property value.
This example illustrates how to use the Validate<TValue>(PropertyInfo, TValue) method to validate the given property value.
This example illustrates how to use the Validate<TValue>(Expression<Func<TValue>>, TValue, ValidationContext) method to validate the given property value.
This example illustrates how to use the Validate<TValue>(PropertyInfo, TValue, ValidationContext) method to validate the given property value.
Methods
View SourceValidate(object)
Validates all properties of the given instance.
Declaration
[Obsolete("This method created obsolete PropertyErrors.")]
public static List<IError> Validate(object instance)
Parameters
| Type | Name | Description |
|---|---|---|
| object | instance | The object instance that is validated. |
Returns
| Type | Description |
|---|---|
| List<IError> | A list of IError. |
Validate<TValue>(Expression<Func<TValue>>, TValue)
Validates the given value via the IsValid(object) method.
Declaration
public static ValidationResult Validate<TValue>(Expression<Func<TValue>> propertyExpression, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| Expression<Func<TValue>> | propertyExpression | The expression that defines the property to validate. |
| TValue | value | The property value to validate. |
Returns
| Type | Description |
|---|---|
| ValidationResult | The first validation error as ValidationResult or Success if validation succeeds. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The property value type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Validate<TValue>(Expression<Func<TValue>>, TValue, ValidationContext)
Validates the given value via the GetValidationResult(object, ValidationContext) method.
Declaration
public static ValidationResult Validate<TValue>(Expression<Func<TValue>> propertyExpression, TValue value, ValidationContext validationContext)
Parameters
| Type | Name | Description |
|---|---|---|
| Expression<Func<TValue>> | propertyExpression | The expression that defines the property to validate. |
| TValue | value | The property value to validate. |
| ValidationContext | validationContext | The ValidationContext. |
Returns
| Type | Description |
|---|---|
| ValidationResult | The first validation error as ValidationResult or Success if validation succeeds. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The property value type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Validate<TValue>(PropertyInfo, TValue)
Validates the given value via the IsValid(object) method.
Declaration
public static ValidationResult Validate<TValue>(PropertyInfo propertyInfo, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| PropertyInfo | propertyInfo | The PropertyInfo that defines the property to validate. |
| TValue | value | The property value to validate. |
Returns
| Type | Description |
|---|---|
| ValidationResult | The first validation error as ValidationResult or Success if validation succeeds. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The property value type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Validate<TValue>(PropertyInfo, TValue, ValidationContext)
Validates the given value via the GetValidationResult(object, ValidationContext) method.
Declaration
public static ValidationResult Validate<TValue>(PropertyInfo propertyInfo, TValue value, ValidationContext validationContext)
Parameters
| Type | Name | Description |
|---|---|---|
| PropertyInfo | propertyInfo | The PropertyInfo that defines the property to validate. |
| TValue | value | The property value to validate. |
| ValidationContext | validationContext | The ValidationContext. |
Returns
| Type | Description |
|---|---|
| ValidationResult | The first validation error as ValidationResult or Success if validation succeeds. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The property value type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Validate<TInstance>(TInstance)
Validates all property values of the given instance.
Declaration
public static IEnumerable<ValidationResult> Validate<TInstance>(TInstance instance)
Parameters
| Type | Name | Description |
|---|---|---|
| TInstance | instance | The instance that is validated. |
Returns
| Type | Description |
|---|---|
| IEnumerable<ValidationResult> | A list of ValidationResult. |
Type Parameters
| Name | Description |
|---|---|
| TInstance | The instance type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|