InvokeMember

From: Amy (amydudley_at_webmail.co.za)
Date: 02/27/04


Date: 27 Feb 2004 00:39:15 -0800

Hi,

I have the following scenario:

A base class BaseClass as follows:

public abstract class BaseClass
{

     private bool PrivateMethod()
     {
           .
           .
           return true;
     }

     public bool MethodA()
     {
          if(PrivateMethod())
          {
              return MethodB();
          }
          else
              return false;
              
     }

     protected abstract bool MethodB()
     {
     }
}

A class derived from BaseClass:

public DerivedClass:BaseClass
{
     protected bool MethodB()
     {
          .
          .
          return true;
     }
   
}

Now, I want to from a completely seperate app, call Method A (note
that Method A is NOT overridable), using which calls the overridden
Method B:

e.g

//Instantiate Derived Class
Type impType = Type.GetType("DerivedClass");
obj = impType.InvokeMember(null,
        BindingFlags.DeclaredOnly |
        BindingFlags.Public | BindingFlags.NonPublic |
        BindingFlags.Instance | BindingFlags.CreateInstance, null, null, args
        );

//Call MethodA
res = (bool)impType.InvokeMember("MethodA",
        BindingFlags.DeclaredOnly |
        BindingFlags.Public | BindingFlags.NonPublic |
        BindingFlags.Instance | BindingFlags.InvokeMethod
        ,null,obj,null);

This code does not work. I get a MissingMethod Exception when trying
to Invoke MethodA. Is it because MethodA is contained in the base
class and not
in the instantiated class? Any help would be appreciated..