验证父对象时是否可以自动验证复杂的子对象,并将结果包含在已填充的对象中ICollection<ValidationResult>?
如果我运行以下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace ConsoleApplication1
{
public class Person
{
[Required]
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
[Required]
public string Street { get; set; }
[Required]
public string City { get; set; }
[Required]
public string State { get; set; }
}
class Program
{
static void Main(string[] args)
{
Person person = new Person
{
Name = null,
Address …Run Code Online (Sandbox Code Playgroud)