Automapper的用法时,属性名称不同

编程入门 行业动态 更新时间:2024-10-28 06:36:02
本文介绍了Automapper的用法时,属性名称不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们正在使用AutoMapper从Codeplex上为我的目标对象有田结尾的所有属性,即车市场和源对象只是城市。

We are using AutoMapper from Codeplex and for me the destination object has all the properties ending with 'Field', ie cityField and the source object has just city.

我可以使用下面的代码来实现,但所有的属性都只是'现场'后缀,并有20个属性。

I can use the below code to achieve but all of the properties are just suffixed with 'Field' and there are 20 properties.

.ForMember(dest => dest.cityField, opt => opt.MapFrom(origin => origin.City));

有没有其他办法忽略田字时,绘图等,它可以映射,而不使用?.ForMember()20次。

Is there any other way to ignore 'Field' word when mapping and so that it can map without using .ForMember() 20 times?

推荐答案

您可以尝试识别后缀:

Mapper.Initialize(cfg => { cfg.RecognizePostfixes("Field"); cfg.CreateMap<Source, Dest>(); });

认识前缀也适用本地配置文件,如果它只是一组地图,这适用于

Recognizing prefixes also works local to profiles, if it's just a set of maps that this applies to.

更多推荐

Automapper的用法时,属性名称不同

本文发布于:2023-11-09 10:46:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572169.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   名称   Automapper

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!