In this link we can set Automapper to skip null value from source object. Can we configure the condition for all classes automatically? Thanks.
Asked
Active
Viewed 224 times
1
-
1I 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 Answers
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