Giter Site home page Giter Site logo

dataannotationsvalidatorrecursive's Introduction

DataAnnotationsValidatorRecursive

The helper will recursively traverse your object graph and invoke validation against DataAnnotations. This originated from following Stackoverflow answer: http://stackoverflow.com/a/8090614/605586

Installation

Available as NuGet-Package dataannotationsvalidator:

Install-Package dataannotationsvalidator

Usage

See file DataAnnotationsValidator/DataAnnotationsValidator.Tests/DataAnnotationsValidatorTests.cs

Short example:

var validator = new DataAnnotationsValidator.DataAnnotationsValidator();
var validationResults = new List<ValidationResult>();

validator.TryValidateObjectRecursive(modelToValidate, validationResults);

dataannotationsvalidatorrecursive's People

Contributors

borismod avatar joewirtley avatar remcoros avatar reustmd avatar rogersillito avatar wald-tq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dataannotationsvalidatorrecursive's Issues

Validate Root IEnumerable

Hello,

The TryValidateObjectRecursive method doesn't work if the root object itself is IEnumerable.

e.g.
List<ThingToValidate> stuff

TryValidateObjectRecursive(stuff) does zero validation. You need a property of the root object that is enumerable.

License and nuget package

Could you please choose a license and add it to the repo?
Could you please publish this project as a nuget package? I can help with that if needed

for list of complex object its not validating.

I have used your Nuget package to use the your DataAnnotationsValidatorRecursive. Below is the simplified version of my code. I am not getting validation error for List although i am getting validation errors for ID. Please help.

public class Program
{
static void Main(string[] args)
{
var child = new Child();
var validationResults = new List();
child.clientAddress = new List { new MyAddress { Address1 = "", Address2 = "", Address3 = "", ZipCode = 0, State = "", City = "" } };

        child.BaseValidator = new DataAnnotationsValidator.DataAnnotationsValidator();
        child.BaseValidator.TryValidateObjectRecursive(child, validationResults);
        if (validationResults.Count > 0)
        {
            child.LogValidationResult(validationResults);
        }

}
}

public class Child: Base
{
[Required]
public int ID{ get; set; };

    [Required]
    public List<MyAddress> myAddress;

}

public class MyAddress {
[Required]
[StringLength(40)]
public string Address1 { get; set; }

    public string Address2 { get; set; }

    [Required]
    [StringLength(40)]
    public string Address3 { get; set; }

    [Required]
    [StringLength(9, MinimumLength = 5, ErrorMessage = "ZipCode minimum length is 5 and maximum length is 9.")]
    public int ZipCode;

    [Required]
    [StringLength(2)]
    public string State { get; set; }

    [Required]
    [StringLength(40, MinimumLength = 1, ErrorMessage = "city minimum length is 1 and maximum length is 40.")]
    public   string City{ get; set; }
}

public abstract class Base : IValidatableObject
{
public IDataAnnotationsValidator BaseValidator;

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        //TODO:loop the validation results

        throw new NotImplementedException();
    }


    public void LogValidationResult(List<ValidationResult> resultList)
    {
        //TODO: Log validation result.
    }
}

Strong name signature not valid for this assembly

Hi,
After I updated to version 2.0 I'm getting exception from ClickOnce:

Following failure messages were detected:
+ Strong name signature not valid for this assembly DataAnnotationsValidator.dll.

To solve the problem I compiled the code locally and included it with my application without a signature.
Version 1.x worked fine.

It should be compatible with .net core

I'm looking forwarding to be able to use that on my .net core app, but I can't install the nugget package because it isn't compatible with .net core (2.0).

The output is

Restoring packages for <path>
Package DataAnnotationsValidator 2.2.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package DataAnnotationsValidator 2.2.0 supports: net471 (.NETFramework,Version=v4.7.1)
Package restore failed. Rolling back package changes for 'DCMessenger.Contracts'.
Time Elapsed: 00:00:00.0655642
========== Finished ==========

v1.0.0.7 made breaking changes

Hello,

We're using your library (thanks for it!) and have just updated our packages to the latest version. This caused the following error during runtime:

[System.MissingMethodException] Method not found: 'Boolean DataAnnotationsValidator.DataAnnotationsValidator.TryValidateObjectRecursive(!!0, System.Collections.Generic.List`1<System.ComponentModel.DataAnnotations.ValidationResult>)'.

This is probably caused by changes made to the signature of the method. We had to revert to v1.0.0.1 in order to fix this issue. Please be aware that such breaking changes should only be done in a new major version, as per Semantic Versioning, to avoid breaking your users.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.