Skip to content

czy5074/RecursiveDataAnnotationsValidation

 
 

Repository files navigation

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 recurisvely 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.

About

Recurisively validate DataAnnotations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%