我们有两个班:
public class Foo
{
public int A { get; set; }
public int B { get; set; }
public int C { get; set; }
}
public class Bar
{
public int A { get; set; }
public int B { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和映射配置
Mapper.CreateMap<Foo, Bar>;
Run Code Online (Sandbox Code Playgroud)
Automapper是否有可能自动检查所有源属性是否具有相应的目标属性,在我的示例中抛出异常,通知我们Foo.C属性未映射到任何内容.Mapper.AssertConfigurationIsValid()只检查相反的方向 - 所有目标属性都有源属性,因此在我的情况下它没有帮助.