使用 c# 2.0 语法的 AutoMapper
我正在尝试使用 AutoMapper 创建自定义映射,但无法将 3.0 语法与 lambda 一起使用。如何将这个 3.0 代码转换为 2.0 代码?
Mapper.CreateMap<MyClass, MyDto>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.CompanyName))
编辑:
由于没有更好的解决方案,我们现在在一台工作站上使用 vs2008 来进行这些映射并构建 dll。我希望我们很快就会升级到vs2010。
I'm trying to create a custom mapping with AutoMapper, but I can't use 3.0 syntax with lambdas. How would one convert this 3.0 code into 2.0 ?
Mapper.CreateMap<MyClass, MyDto>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.CompanyName))
Edit:
Since there was no better solution, we are now using vs2008 on one workstation to make these mappings and build a dll. I hope it won't be long until we upgrade to vs2010.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:吉米在评论中提到 AutoMapper 使用表达式树。这并不能立即排除使用 .NET 2.0 的可能性(您可以使用 Mono 的 System.Core 实现),但如果您甚至不能使用 C# 3,则必须构建所有手动创建表达式树,这将是一个巨大的痛苦。
您是否绝对禁止使用.NET 3.5 和 C# 3?
EDIT: Jimmy has mentioned in the comments that AutoMapper uses expression trees. That doesn't immediately rule out the possibility of using .NET 2.0 (you can use Mono's implementation of System.Core), but if you can't even using C# 3 you'll have to construct all the expression trees manually, which it going to be a huge pain.
Are you absolutely prohibited from using .NET 3.5 and C# 3?