【发布时间】:2011-02-26 07:47:35
【问题描述】:
我遇到了一个关于泛型类的问题。我很困惑如何使用参数调用构造函数。
我的界面:
Public Interface IDBObject
Sub [Get](ByRef DataRow As DataRow)
Property UIN() As Integer
End Interface
我的孩子班:
Public Class User
Implements IDBObject
Public Sub [Get](ByRef DataRow As System.Data.DataRow) Implements IDBObject.Get
End Sub
Public Property UIN() As Integer Implements IDBObject.UIN
Get
End Get
Set(ByVal value As Integer)
End Set
End Property
End Class
我的下一堂课:
Public Class Users
Inherits DBLayer(Of User)
#Region " Standard Methods "
#End Region
End Class
我的 DBObject 类:
Public Class DBLayer(Of DBObject As {New, IDBObject})
Public Shared Function GetData() As List(Of DBObject)
Dim QueryString As String = "SELECT * ***;"
Dim Dataset As DataSet = New DataSet()
Dim DataList As List(Of DBObject) = New List(Of DBObject)
Try
Dataset = Query(QueryString)
For Each DataRow As DataRow In Dataset.Tables(0).Rows
**DataList.Add(New DBObject(DataRow))**
Next
Catch ex As Exception
DataList = Nothing
End Try
Return DataList
End Function
End Class
我在 DBLayer 对象的星标区域出现错误。
可能的原因是什么?我该怎么做才能解决它?
我什至想在 IDBObject 接口中添加 New(byval someval as datatype) 用于重载构造。但它也给出了一个错误?我该怎么做?
添加
IDBObject 中的 Sub New(ByVal DataRow As DataRow) 产生以下错误 不能在接口中声明“Sub New”。
DBLayer 对象中产生的错误 行:DataList.Add(新 DBObject(DataRow)) 消息:参数不能传递给类型参数上使用的“新”。
【问题讨论】:
标签: vb.net generics class inheritance interface