InvokeMember

  • Thread starter Thread starter Amy
  • Start date Start date
A

Amy

Hi,

I have the following scenario:

A base class BaseClass as follows:

public abstract class BaseClass
{

private bool PrivateMethod()
{
 
Amy said:
//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..

You've specified "DeclaredOnly" which means:

<quote>
Specifies that only members declared at the level of the supplied
type's hierarchy should be considered. Inherited members are not
considered.
</quote>

Getting rid of that may well fix it.
 
Back
Top