Class RecursiveValidator
- Namespace
- Acuit.Pinpoint.Common.Validation
- Assembly
- Acuit.Pinpoint.Common.dll
Defines a helper class that can be used to validate options using data annotation attributes.
public static class RecursiveValidator
- Inheritance
-
RecursiveValidator
- Inherited Members
Remarks
This helper is similar to the Validator class, except that it recursively validates nested objects and collections.
Methods
DefaultPropertyFilter(PropertyInfo)
The default property filter used by TryValidateObject(object, ICollection<ValidationResult>).
public static bool DefaultPropertyFilter(PropertyInfo propertyInfo)
Parameters
propertyInfo
PropertyInfoInformation about the property to check.
Returns
Remarks
This will filter out properties that match any of the following:
- The property is of or descended from type Exception.
- The property is of or descended from type SerialPort (.NET Framework 4 only).
- The property has a BrowsableAttribute attribute with Browsable set to false.
Exceptions
- ArgumentNullException
propertyInfo
is null.
TryValidateObject(object, ICollection<ValidationResult>)
Determines whether the specified object is valid, recursively validating nested objects and collections.
public static bool TryValidateObject(object instance, ICollection<ValidationResult> validationResults)
Parameters
instance
objectThe object to validate.
validationResults
ICollection<ValidationResult>An optional collection to hold each failed validation.
Returns
Remarks
After validating the top-level properties of instance
, nested properties that meet the following requirements will be recursively validated:
- The property has a getter.
- The property is not a value or string type.
- The property does not have any indexers.
- The property is not filtered out via DefaultPropertyFilter(PropertyInfo).
Exceptions
- ArgumentNullException
instance
is null.- TargetInvocationException
A nested property value could not be retrieved.
TryValidateObject(object, ICollection<ValidationResult>, Func<PropertyInfo, bool>)
Determines whether the specified object is valid, recursively validating nested objects and collections.
public static bool TryValidateObject(object instance, ICollection<ValidationResult> validationResults, Func<PropertyInfo, bool> propertyFilter)
Parameters
instance
objectThe object to validate.
validationResults
ICollection<ValidationResult>An optional collection to hold each failed validation.
propertyFilter
Func<PropertyInfo, bool>A predicate that filters which properties are recursively validated. It should return true to validate a property recursively, or false to skip it.
Returns
Remarks
After validating the top-level properties of instance
, nested properties that meet the following requirements will be recursively validated:
- The property has a getter.
- The property is not a value or string type.
- The property does not have any indexers.
- The property is not filtered out via
propertyFilter
.
Exceptions
- ArgumentNullException
instance
is null.- ArgumentNullException
propertyFilter
is null.- TargetInvocationException
A nested property value could not be retrieved.