Use reflection to call base class implementation of virtual method

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to use reflection to lookup and invoke a specific instance of a
virtual method on a class. I can get the method easy enough, but the Invoke
method of MethodInfo states that it calls the correct virtual method based on
the passed in instance type. The problem is it doesn't point out a way to
invoke a specific instance of an implementation in the inheritance hierarchy.

I'm essentially attempting to invoke the base.MyMethod through reflection,
but can't find any way to do so. Any ideas?
 
Jay,
I think the user of client should NOT have the option of applying the
virtual method implementation of a superclass to a subclass instance. The
reason is that it may not work, even worse, it could break the application.
Only the author of the subclass is in the position to datamine whether those
virtual method implementations of it's parent should be exposed to client or
not.

Regards
Ming Chen
 
Whether or not this should be done is not what I'm asking. I'm asking for a
solution to a problem I have. If it can't be done, fine. If it can, I want
to know how.

I've figured out a way to call a base class private interface implementation
when an interface is reimplemented in a derived class (using
Type.InterfaceMapping) and now I want to know if I can do it on public
virtual methods. It must be possible, after all I can code it directly in
the language syntax. I just can't find a reflection API method to allow me
to do the same thing. If I can do it one way, why am I not allowed to do the
same thing a different way?

I find that intellectual arguments about object oriented design purity can
be very interesting, but often get in the way of solving the real problems
that I have right now.
 
Back
Top