我有一些这样的代码:
Public Function MakeDatareaderList(Of I As New)(ByVal objDR As DbDataReader) As List(Of I)
Dim list As List(Of I)
Mapper.CreateMap(Of DbDataReader, List(Of I))()
list = Mapper.Map(Of SqlDataReader, List(Of I))(CType(objDR, SqlDataReader))
Return list
End Function
按预期工作,即传入一个类型,然后返回该类型的列表。我可以这样做吗?
Public Function MakeDatareaderFirst(Of I As New)(ByVal objDR As DbDataReader) As I
Mapper.CreateMap(Of IDataReader, IEnumerable(Of I))()
I = Mapper.Map(Of IDataReader, IEnumerable(Of typeUSN))(objDR).First()
Return I
End Function
在上面的代码中,错误是:I不能用作表达式。上面的代码返回一个填充了数据的对象。
您还没有创建一个变量来分配映射器函数的结果给您吗?您试图将其分配给类型I
Public Function MakeDatareaderFirst(Of I As New)(ByVal objDR As DbDataReader) As I
Dim instance as I
Mapper.CreateMap(Of IDataReader, IEnumerable(Of I))()
instance = Mapper.Map(Of IDataReader, IEnumerable(Of I))(objDR).First()
Return instance
End Function