Generics

G

Guest

i have a generic class

Public Class ACollection(Of T)
Inherits BindingList(Of T)

where BaseDataClass is declared mustinherit

i then have some code that loadss the collection

With oSQLDR ' a datareader
If .HasRows Then
Do While .Read = True

'Create new instance of appropriate businees object
then populate
Dim o As Object = Me.AddNew
busObject = CType(o, IDataClass)
busObject.clientConnection = Me.ClientConnection
busObject.Populate(oSQLDR)
Loop
End If
End With

this all works fine

however if i change this collection to

Public Class ACollection(Of BaseCLass)

how, when using AddNew in the above code do i get addnew to add the correct
type of object (which inherits from BaseClass)

guyy
 
J

Jim Wooley

I believe you need to change your line
Dim o as Object = Me.AddNew
to
Dim o as T = Me.AddNew

Jim Wooley
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top