[英]Automapper in VB.Net
I am having a devil of a time attempting to translate the following piece of code from c# to VB.Net.我有一段时间试图将以下代码从 c# 翻译成 VB.Net。 I have little experience in VB.Net and all my searches have proven fruitless to date.
我对 VB.Net 的经验很少,迄今为止我的所有搜索都没有结果。
IMapper DataReaderMapper = new MapperConfiguration(cfg => {
cfg.AddDataReaderMapping();
cfg.CreateMap<IDataReader, MyDTO1>();
cfg.CreateMap<IDataReader, MyDTO2>();
cfg.CreateMap<IDataReader, MyDTO3>();
}).CreateMapper();
The code is using the Automapper and Automapper.Data nuget packages to map datatables to DTOs.该代码使用 Automapper 和 Automapper.Data nuget 包到 map 数据表到 DTO。 I know the code works fine in c#.
我知道代码在 c# 中运行良好。
My best guess was the following:我最好的猜测如下:
Dim DataReaderMapper As IMapper = New MapperConfiguration(Function(cfg) {cfg.AddDataReaderMapping(), cfg.CreateMap(Of IDataReader, MyDTO1)()}).CreateMapper()
The above results in an "Overload resolution failure" warning as I am obviously not passing in the arguments/parameters in the correct fashion/order.上面的结果导致“过载解析失败”警告,因为我显然没有以正确的方式/顺序传递参数/参数。 I can usually muddle by with most translations that I have to deal with but this one is stumping me.
我通常可以应付大多数我必须处理的翻译,但这个让我很困惑。 Any help would be appreciated.
任何帮助,将不胜感激。
According to https://converter.telerik.com/根据https://converter.telerik.com/
Dim DataReaderMapper As IMapper = New MapperConfiguration(Function(cfg)
cfg.AddDataReaderMapping()
cfg.CreateMap(Of IDataReader, MyDTO1)()
cfg.CreateMap(Of IDataReader, MyDTO2)()
cfg.CreateMap(Of IDataReader, MyDTO3)()
End Function).CreateMapper()
I was able to resolve by combining the responses of Nick Abbot's Telerik conversion and Craig's suggestion to swap out "Function" for "Sub" to get the following:我能够通过结合 Nick Abbot 的 Telerik 转换的响应和 Craig 将“Function”换成“Sub”的建议来解决问题,以获得以下内容:
Dim DataReaderMapper As IMapper = New MapperConfiguration(Sub(cfg)
cfg.AddDataReaderMapping()
cfg.CreateMap(Of IDataReader, MyDTO1)()
cfg.CreateMap(Of IDataReader, MyDTO2)()
cfg.CreateMap(Of IDataReader, MyDTO3)()
End Sub).CreateMapper()
Thank you gentlemen for your assistance!谢谢各位先生的协助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.