条件映射

AutoMapper allows you to add conditions to properties that must be met before that property will be mapped.

This can be used in situations like the following where we are trying to map from an int to an unsigned int.

class Foo{
  int baz;
}

class Bar { 
  uint baz; 
}

In the following mapping the property baz will only be mapped if it is greater than or equal to 0 in the source object.

Mapper.Initialize(cfg => {
  cfg.CreateMap<Foo,Bar>()
    .ForMember(dest => dest.baz, opt => opt.Condition(src => (src.baz >= 0))); 
});
原文地址:https://www.cnblogs.com/Leman/p/5774010.html