From: Peter Duniho on
J.B. Moreno wrote:
> I agree that it's a bad idea, but
>
> A a = (A) this;
> a.m();
>
> or something like it should work...

No, that definitely should not work. The whole point of a virtual
member is so that you always get the polymorphic behavior regardless of
the static (compile-time) type used to access the instance.

If you want to have the method called depend on the declared type of the
variable used to access the instance, then don't make the method virtual.

Pete
From: Jeff Johnson on
"Arne Vajh�j" <arne(a)vajhoej.dk> wrote in message
news:4c2be245$0$282$14726298(a)news.sunsite.dk...

>>> I'll have a look at what I can do via reflection.
>>
>> That's easy: anything.
>
> There are a few things it can't: make peace in the
> middle east etc..

That's because the attitudes on both sides are unmanaged....


From: Jeff Johnson on
"J.B. Moreno" <planB(a)newsreaders.com> wrote in message
news:300620102047515905%planB(a)newsreaders.com...

> I agree that it's a bad idea, but
>
>
> A a = (A) this;
> a.m();
>
> or something like it should work...

It absolutely will not work. I questioned this myself a while back when I
was just getting into C# and I wrote a simple app to test it. No matter what
you do to the derived class, whether you cast it to the base class or you
create a variable of type base and assign a derived instance to it, when you
call an overridden method you get the DERIVED class's version of the method.
If you need the base class's version you have to add an extra method to the
derived class and explicitly call base.Method() from there.


From: Duncan on
I'm having trouble finding a working example of what I need.

Assuming I'm in the overridden m() for class C, how can I call A.m()
from there using reflection?

Thanks,
-Duncan
From: Jeff Johnson on
"Duncan" <a(a)b.com> wrote in message
news:uZkSrsSGLHA.5160(a)TK2MSFTNGP04.phx.gbl...

> I'm having trouble finding a working example of what I need.
>
> Assuming I'm in the overridden m() for class C, how can I call A.m() from
> there using reflection?

Ohhh, I may have been coming at this from the wrong direction. In my mind I
was envisioning using Reflection to instantiate an A object and call a
protected member on it. You have a C object and want to dig down into its A
ancestor. That might not be possible at all. Sorry if I confused you.

Can you give us a concrete example of what you're trying to do? Real class
and method names, not A/B/C/m. Perhaps we can suggest workarounds.