views:

50

answers:

1

I apologize if that title is confusing. This question may be a result of lack of coffee and/or sleep, but my mind is not working correctly right now.

Anyways, I have an inheritance tree like so (I know the architecture isn't ideal):

BaseClass

GeneralForm : Inherits BaseClass

SpecificForm : Inherits GeneralForm

And an object like so:

MyItem

MySpecificItem : Inherits MyItem

I have Items As List (Of MyItem) as a property in BaseClass. I would like for SpecificForm to somehow override Items to return type List (Of MySpecificItem). I feel like this is easy to do, but again, my head is spinning and I can't think straight at the moment.

Thanks so much in advance.

EDIT

If the above isn't possible, is it possible to take a List (Of MyItem) and turn it into a List (Of MySpecificItem)? MySpecificItem has just one additional property that is specific to SpecificForm, but I NEED it.

Anyone? :\

A: 

You should be able in SpecificForm to just do the following...

Private pMySpecificItems As List(Of MySpecificItem)

Public Shadows ReadOnly Property Items() As List(Of MySpecificItem) 
    Get 
        Return pMySpecificItems
    End Get 
End Property

The 'Shadows' keyword will tell the compiler that this property in SpecificForm hides the Items property from the base-class form.

You can't actually delegate to the base class' property and "cast" it to List(Of MySpecificItem) because while a sub-class may be viewed as an instance of its base class, a base class object cannot be cast to an instance of a sub-class (as the sub-class may have added required properties/state that the base class does not support or implement).

eidylon