How to pass a class and a method name as strings and invoke that class' method?
Like
void caller(string myclass, string mymethod){
// call myclass.mymethod();
}
Thanks
How to pass a class and a method name as strings and invoke that class' method?
Like
void caller(string myclass, string mymethod){
// call myclass.mymethod();
}
Thanks
Something like this:
You should modify the binding flags according to the method you wish to call, as well as check the Type.InvokeMember method in msdn to be certain of what you really need.
What's your reason for doing this? More than likely you can do this without reflection, up to and including dynamic assembly loading.
You will want to use reflection.
Here is a simple example:
Now this is a very simple example, devoid of error checking and also ignores bigger problems like what to do if the type lives in another assembly but I think this should set you on the right track.