[英]How to tell Automapper to check if all source properties have destination properties
We have two classes: 我们有两个类:
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; }
}
and mapping configuration 和映射配置
Mapper.CreateMap<Foo, Bar>;
Is there some possibility for Automapper to check automatically that all source properties have corresponding destination properties, in my example throwing an exception which notifies us about Foo.C property not mapped to anything. Automapper是否有可能自动检查所有源属性是否具有对应的目标属性,在我的示例中,抛出一个异常,通知我们有关Foo.C属性未映射到任何内容的异常。 Mapper.AssertConfigurationIsValid() checks only the other way round - that all destination properties have source properties so it doesn't help in my case.
Mapper.AssertConfigurationIsValid()仅以另一种方式进行检查-所有目标属性都具有源属性,因此对我而言无济于事。
Maybe you can use a hack and test the mapping in the other direction. 也许您可以使用hack并从另一个方向测试映射。 Something like:
就像是:
Mapper.CreateMap<Bar, Foo>; // Swap the direction of the mapping
Mapper.AssertConfigurationIsValid()
I know it isn't ideal but could be a quick solution. 我知道这不是理想的选择,但可以快速解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.