Using DynamicMap() and ignore null source value

时间秒杀一切 提交于 2019-12-18 12:55:09

问题


I'm using Mapper.DynamicMap() inside a generic method and would like to, without using .CreateMap(), ignore some any source values that are null. Is this even possible?


回答1:


If you want all source properties with null values to be ignored you could use:

Mapper.CreateMap<SourceType, DestinationType>()
                    .ForAllMembers(opt => opt.Condition(srs => !srs.IsSourceValueNull));

Otherwise, you can do something similar for each member. This will get quit tedious if there are a large number of properties.




回答2:


I solved it with DataMember property in destination type [DataMember(EmitDefaultValue = false)] add this in the destination DTO



来源:https://stackoverflow.com/questions/3704512/using-dynamicmap-and-ignore-null-source-value

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