Created
October 23, 2011 19:31
-
-
Save motowilliams/1307769 to your computer and use it in GitHub Desktop.
Extension-Methods-Improving-the-quality-of-Life
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ValidationExtensions | |
{ | |
public static List<ValidationResult> ValidateAnnotations<T>(this T value) where T : class | |
{ | |
if(value == null) return new List<ValidationResult>(); | |
var validationContext = new ValidationContext(value, null, null); | |
var validationResults = new List<ValidationResult>(); | |
Validator.TryValidateObject(value, validationContext, validationResults, true); | |
return validationResults; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment