1

I am using Emit mapper to copy values from one object to the other.

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? The .Map method itself does not take any additional parameters to ignore certain properties. I can specify fields to be ignored using DefaultMapConfig, but that is static and cannot be changed during mapping.

Please help.

Shreedhar Kotekar
  • 1,034
  • 10
  • 20

1 Answers1

3

You have to configure the Mapper:

string[] fieldsToIgnore = { "NameOfThePropertyToIgnore" };

var mapper = ObjectMapperManager.DefaultInstance
        .GetMapper<SourceClass, DestClass>(
          new DefaultMapConfig()
            .IgnoreMembers<SourceClass, DestClass>(fieldsToIgnore)
        );
onof
  • 17,167
  • 7
  • 49
  • 85