Allows recursive validation of sub-objects in a class when using DataAnnotations validation (also known as Attribute Validation). The current version of .NET Core's attribute validation does not handle objects within objects (or collections of objects). Therefore it is necessary to add some glue code to recurse through the object graph.
$ dotnet add package RecursiveDataAnnotationsValidation
PM> Install-Package RecursiveDataAnnotationsValidation
Usage of the recursive validation is nearly identical to using the standard validator.
var validator = new RecursiveDataAnnotationValidator();
var validationResults = new List<ValidationResult>();
var result = validator.TryValidateObjectRecursive(sut, validationResults);
There are more examples in the example and test projects.
The [SkipRecursiveValidation]
attribute can be used on properties where you do not want to recursively validate. An example of this can be seen in SkippedChildrenExample.cs.
https://www.nuget.org/packages/RecursiveDataAnnotationsValidation/
This package grew out of a need to recursively validate POCOs used for the .NET Core options pattern and is based on work by Mike Reust and his DataAnnotationsValidatorRecursive project. After doing a lot of experimentation, I went ahead and forked the project in order to make minor improvements, port it to .NET Standard, and experiment with using Github Actions.