Using Data Annotations Validation Manually and Object Graphs
问题 Let's assume that I have two simple classes: public class CustomerDetails { [Required] public string Address { get; set; } } public class Customer { public Customer() { Details = new CustomerDetails(); } [Required] public string Name { get; set; } public CustomerDetails Details { get; private set; } } When I try to manually validate Customer class in a Console application in this way: var customer = new Customer() { Name = "Conrad" }; var context = new ValidationContext(customer, null, null);