Re: InvokeMember

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 02/27/04


Date: Fri, 27 Feb 2004 08:57:59 -0000

Amy <amydudley@webmail.co.za> wrote:
> //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.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Loading