小编jjj*_*jjj的帖子

如何告诉Automapper检查所有源属性是否都有目标属性

我们有两个班:

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()只检查相反的方向 - 所有目标属性都有源属性,因此在我的情况下它没有帮助.

c# mapping validation automapper automapper-2

8
推荐指数
1
解决办法
863
查看次数

标签 统计

automapper ×1

automapper-2 ×1

c# ×1

mapping ×1

validation ×1