简体   繁体   English

发射映射器在映射时忽略成员

[英]Emit mapper Ignoring member at mapping time

I am using Emit mapper to copy values from one object to the other. 我使用Emit mapper将值从一个对象复制到另一个对象。

When I am mapping the objects, I need to ignore certain fields from being mapped/copied over. 当我映射对象时,我需要忽略某些字段被映射/复制。 The fields to be ignored keeps changing based on scenario. 要忽略的字段会根据方案不断变化。

How can this be done in EmitMapper? 如何在EmitMapper中完成? The .Map method itself does not take any additional parameters to ignore certain properties. .Map方法本身不会使用任何其他参数来忽略某些属性。 I can specify fields to be ignored using DefaultMapConfig, but that is static and cannot be changed during mapping. 我可以使用DefaultMapConfig指定要忽略的字段,但这是静态的,并且在映射期间无法更改。

Please help. 请帮忙。

You have to configure the Mapper: 您必须配置Mapper:

string[] fieldsToIgnore = { "NameOfThePropertyToIgnore" };

var mapper = ObjectMapperManager.DefaultInstance
        .GetMapper<SourceClass, DestClass>(
          new DefaultMapConfig()
            .IgnoreMembers<SourceClass, DestClass>(fieldsToIgnore)
        );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM