问题
In this link we can set Automapper to skip null value from source object. Can we configure the condition for all classes automatically? Thanks.
回答1:
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.
来源:https://stackoverflow.com/questions/32621702/automapper-skip-null-values-for-all-classes