jjj*_*jjj 8 c# mapping validation automapper automapper-2
我们有两个班:
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()只检查相反的方向 - 所有目标属性都有源属性,因此在我的情况下它没有帮助.
也许您可以使用 hack 并测试另一个方向的映射。就像是:
Mapper.CreateMap<Bar, Foo>; // Swap the direction of the mapping
Mapper.AssertConfigurationIsValid()
Run Code Online (Sandbox Code Playgroud)
我知道这并不理想,但可能是一个快速的解决方案。
| 归档时间: |
|
| 查看次数: |
863 次 |
| 最近记录: |