使用DynamicMap()并忽略空源值 [英] Using DynamicMap() and ignore null source value

查看:156
本文介绍了使用DynamicMap()并忽略空源值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通用方法中使用了 Mapper.DynamicMap(),并且希望使用 .CreateMap(),忽略一些任何为空的源值。

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?

推荐答案

如果您希望忽略所有具有空值的源属性,则可以使用:

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.

这篇关于使用DynamicMap()并忽略空源值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆