DataAnnotations validation from a class
问题 I am using DataAnnotations in a project that is a pure C# application, what is the best way to validate my models/documents against the DataAnnotations attributes? 回答1: This is now build into C# 4 var result = new List<ValidationResult>(); bool valid = Validator.TryValidateObject(Vehicle, new ValidationContext(Vehicle, null, null), result); This will also give you the details of the validation. 回答2: Not from me but my friend Steve Sanderson: internal static class