So, i have an assembly that i loaded into the interface, and it works perfectly:
MarshalByRefObject pluginObject = ...
ecko.Plugins.Interface.Plugin plug = pluginObject as ecko.Plugins.Interface.Plugin;
but, allthough i will have alot of methods in the interface, i will have to execute methods that are dynamic, and determined from information in the interface.. so basically, i need to call methods that are not in my interface, and i wont know the name of until last minute..
this is what i have tried (using the “Execute” methods as an example):
plug.GetType().GetMethod("Execute").Invoke((what-the-hell-do-i-put-here), new object[] { });
am i on the right track? please guide me 🙂
thanks.
If you want to use Reflection then the missing piece in your code is:
The first parameter of the
Invokemethod should be the instance that you want to invoke the method on. This is required becausemethis just an abstract description of the method (and is not associated with any instance). This is useful if you want to call the method on multiple instances (you could cache themethvalue).If you’re using C# 4.0, then you can use the new
dynamicfeature (assuming that “Execute” is a name that does not change):If a variable is declared as
dynamicin C# 4.0, then you can call any methods you want and the method resolution will be done at runtime (similar to Reflection, but a bit more complicated and a bit more efficient).