Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DynamicMap() and ignore null source value

Tags:

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?

like image 352
JoseMarmolejos Avatar asked Sep 13 '10 21:09

JoseMarmolejos


1 Answers

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.

like image 168
Prin Avatar answered Oct 19 '22 00:10

Prin