By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Generics

P: n/a
guy
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
Feb 8 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I believe you need to change your line
Dim o as Object = Me.AddNew
to
Dim o as T = Me.AddNew

Jim Wooley

"guy" <gu*@discussions.microsoft.com> wrote in message
news:B2**********************************@microsof t.com...
i have a generic class
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)

Feb 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.