B
Brett
I have a class 'Sample'. From it I have derived a class SampleExt that
provides a couple more methods and properties. My app initially uses the
Sample class, but there is an area of the application where I need to access
the methods and properties in SampleExt. What I'm trying to do is cast a
Sample to a SampleExt reference, the compiler allows it but the runtime
throws an InvalidCastException.
For example:
Function Whatever (pSample as Sample)
Dim x as SampleExt
x = CType (pSample, SampleExt)
x.ExtendedMethod
End Function
I have read statements that say this is possible and others that say it is
not. Can anyone clear it up unequivocally for me. I swear I done this
before, but maybe I was always upcasting....
If you are just going to respond with "Why don't you just <fill in the
blank>" suggesting that I do this some other way please save your time. I
have specific reasons for wanting to do it this way and they are too complex
(and irrelevant to this discussion) to include them here.
Thanks in advance.
Brett
provides a couple more methods and properties. My app initially uses the
Sample class, but there is an area of the application where I need to access
the methods and properties in SampleExt. What I'm trying to do is cast a
Sample to a SampleExt reference, the compiler allows it but the runtime
throws an InvalidCastException.
For example:
Function Whatever (pSample as Sample)
Dim x as SampleExt
x = CType (pSample, SampleExt)
x.ExtendedMethod
End Function
I have read statements that say this is possible and others that say it is
not. Can anyone clear it up unequivocally for me. I swear I done this
before, but maybe I was always upcasting....
If you are just going to respond with "Why don't you just <fill in the
blank>" suggesting that I do this some other way please save your time. I
have specific reasons for wanting to do it this way and they are too complex
(and irrelevant to this discussion) to include them here.
Thanks in advance.
Brett