1

In this link we can set Automapper to skip null value from source object. Can we configure the condition for all classes automatically? Thanks.

Community
  • 1
  • 1
stenlytw
  • 938
  • 13
  • 18
  • 1
    I don't think you can configure *anything* for all classes automatically in Automapper, you'll have to write the code yourself. – Andrew Savinykh Sep 17 '15 at 04:33

1 Answers1

0

You can do something like:

            Mapper.Initialize(cfg =>
            {
                cfg.ForAllMaps((typeMap, map) =>
                    map.ForAllOtherMembers(opt => opt.Condition((src, dest, srcMem, destMem) => src != null)));
}

I used ForAllOtherMembers so that it does not override your other conditions that you may declare individually.

DonO
  • 1,030
  • 1
  • 13
  • 27