开发者

AutoMapper - how to use type converter on a single property

开发者 https://www.devze.com 2023-03-13 07:22 出处:网络
Is it possible to use AutoMapper with a single property? I would like to convert a string value of comma delimited values to a list of values separated by a line feed on the UI.

Is it possible to use AutoMapper with a single property? I would like to convert a string value of comma delimited values to a list of values separated by a line feed on the UI.

The current custom converters only seem to work at the class level, a开发者_如何学Gond because the dest and source types are both string I can't create a single map based on .

How would I apply the custom converter on a single property? Or should the custom resolver be used instead?


You may use a custom resolver or map the property by calling your convert logic in a MapFrom lambda:

Mapper.CreateMap<TSource, TDest>().ForMember(dto => dto.DestPrp,
                                                        e => e.MapFrom(o => ConvertTo(o.SourceProp)))
0

精彩评论

暂无评论...
验证码 换一张
取 消