Adam_Zehavi
14 years agoOccasional Contributor
How to invoke a C# script method, reflectively?
Hi,
I have a many functions spread over vast number of script files, I may invoke any one of them from a single "main" method using a string to describe the method. currently I use a very long switch case and I would like to know if there is a way to use the method name as the string and invoke the method reflectively?
TODAY:
function runner(methodName, params) {
switch(methodName) {
case function1:
run function1(params);
case function2:
...
...
...
and so on.
}
I don't like this approach, I would like to use the name to get a reference to the method:
function runner(methodName, params) {
var method = getReflectiveMethod(methodName);
method["invoke"](params);
}
is this possible?
Adam.
I have a many functions spread over vast number of script files, I may invoke any one of them from a single "main" method using a string to describe the method. currently I use a very long switch case and I would like to know if there is a way to use the method name as the string and invoke the method reflectively?
TODAY:
function runner(methodName, params) {
switch(methodName) {
case function1:
run function1(params);
case function2:
...
...
...
and so on.
}
I don't like this approach, I would like to use the name to get a reference to the method:
function runner(methodName, params) {
var method = getReflectiveMethod(methodName);
method["invoke"](params);
}
is this possible?
Adam.