Automapper skip null values for all classes

ε祈祈猫儿з 提交于 2021-01-28 08:12:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!