Skip to content

Latest commit

 

History

History
39 lines (21 loc) · 2.55 KB

File metadata and controls

39 lines (21 loc) · 2.55 KB

RecursiveDataAnnotationsValidation

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.

Installation

.NET Core

$ dotnet add package RecursiveDataAnnotationsValidation

Package Manager

PM> Install-Package RecursiveDataAnnotationsValidation

Usage

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.

SkipRecursiveValidationAttribute

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.

Build Status

.NET Core

Nuget Page

https://www.nuget.org/packages/RecursiveDataAnnotationsValidation/

Legacy

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.