Generic Class Vb.net

Posted by KoolKabin on Stack Overflow See other posts from Stack Overflow or by KoolKabin
Published on 2010-06-01T11:44:45Z Indexed on 2010/06/01 12:03 UTC
Read the original article Hit count: 240

Filed under:
|
|
|
|

hi guys,

I am stuck with a problem about generic classes. I am confused how I call the constructor with parameters.

My interface:

Public Interface IDBObject
    Sub [Get](ByRef DataRow As DataRow)
    Property UIN() As Integer
End Interface

My Child Class:

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

My Next Class:

Public Class Users
    Inherits DBLayer(Of User)

#Region " Standard Methods "

#End Region
End Class

My DBObject Class:

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

I get error in the starred area of the DBLayer Object.

What might be the possible reason? what can I do to fix it?

I even want to add New(byval someval as datatype) in IDBObject interface for overloading construction. but it also gives an error? how can i do it?

Adding

Sub New(ByVal DataRow As DataRow) in IDBObject producess following error 'Sub New' cannot be declared in an interface.

Error Produced in DBLayer Object line: DataList.Add(New DBObject(DataRow)) Msg: Arguments cannot be passed to a 'New' used on a type parameter.

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about generics