Automapper: complex if else statement in ForMember

前端 未结 2 1318
执念已碎
执念已碎 2020-12-17 10:50

Assuming the Date is a nullable DateTime:

Mapper.CreateMap()               
             .ForMember(d         


        
2条回答
  •  臣服心动
    2020-12-17 11:27

    In recent versions of AutoMapper, ResolveUsing was removed. Instead, use a new overload of MapFrom:

    void MapFrom(Func mappingFunction);
    

    Just adding another lambda/function parameter will dispatch to this new overload:

            CreateMap()
                    .ForMember(dest => dest.SomeDestProp, opt => opt.MapFrom((src, dest) =>
                    {
                        TSomeDestProp destinationValue;
    
                        // mapping logic goes here
    
                        return destinationValue;
                    }));
    

提交回复
热议问题