| i am calling the method within the generic class
| there are no constraints on the parameter
| > > eg dim Thing as BaseClass=CType(T,BaseClass)
It sounds like you need to add a constraint to the T parameter!
| > > and i know that any object in the collection will inherit from a base
| > > class
Is there a reason the T parameter is not constrained by BaseClass? If you
know that any object in the collection will inherit from a base class, then
adding the constraint will ensure it.
Can you post 10 or 15 lines of class you are using, that shows the
relationship between the class, the T parameter, the BindingList(Of T), and
the CType? As its unclear what you really have & what you are really
trying... Can you post something like:
Public MustInherit Class BaseClass
Public MustOverride Sub DoIt()
End Class
Public Class Something(Of T As BaseClass)
Private m_list As System.ComponentModel.BindingList(Of T)
Public Sub DoIt()
For Each item As T In m_list
item.DoIt()
Next
End Sub
End Class
NOTE: In the above, because T has a BaseClass constraint, we are able to
call any BaseClass method on T variables.
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
| Herfried,
| i am calling the method within the generic class
| there are no constraints on the parameter
|
| the cgeneric collection will be used to hold 1 of a number of classes, all
| of which inherit dfrom the same base class
|
| thanks guy
|
|
|
| "Herfried K. Wagner [MVP]" wrote:
|
| > > if i have a generic collection, say a binding list
| > > MyList as new BindingList (of T)
| > >
| > > and i know that any object in the collection will inherit from a base
| > > class
| > > that i have defined how do i call a base class method on a member of
the
| > > collection?
| > >
| > > i cant seem to cast from T to my base class
| > >
| > > eg dim Thing as BaseClass=CType(T,BaseClass)
| >
| > Where do you want to call the method? Inside the gerneic class or
outside
| > its implementation? Did you specify a constraint on the generic
parameter?
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:
http://dotnet.mvps.org/>
| > V B <URL:
http://classicvb.org/petition/>
| >
| >