Table of Contents

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 PropertyInfo

Information about the property to check.

Returns

bool

true to validate the property recursively, or false to skip it.

Remarks

This will filter out properties that match any of the following:

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 object

The object to validate.

validationResults ICollection<ValidationResult>

An optional collection to hold each failed validation.

Returns

bool

true if the object validates; otherwise, false.

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 object

The 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

bool

true if the object validates; otherwise, false.

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.