Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Non-property oriented validation

$
0
0
I created a sample Extension method... I hope that it could help someone.
         public static void ObjectRule<T>(this AbstractValidator<T> validator, Func<T, string> customValidation)
         {
             validator.Custom(x =>
                                  {
                                      string error = customValidation(x);
                                      if (string.IsNullOrEmpty(error))
                                          return null;
                                      else
                                          return new ValidationFailure(string.Empty, error);
                                  }
                 );
         }
Now the could would be like:
fluentValidator.ObjectRule("TEST OBJECT ERROR");
Any better (cleaner) ideas?


Two questions (do you want me to create new topics?):
  1. Is there an ValidationRule implementation that uses DataAnnotations?
  2. Do you know any good IDataErrorInfo wrapper/adapter (I am currently working at it) :)

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>