如何调用它的名字来作为参数共享功能 [英] How to call a shared function which its name came as a parameter
本文介绍了如何调用它的名字来作为参数共享功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个方法,我想调用哪个名字来作为一个参数,一个共享的功能。
In a method, I want to call a shared function which its name came as a parameter.
例如:
private shared function func1(byval func2 as string)
'call func2
end function
我怎样才能做到这一点?
How can i do it?
推荐答案
您可以使用反射来寻找类和方法。
You can use reflection to find the class and the method.
实例在C#:</ P>
Example in C#:
namespace TestProgram {
public static class TestClass {
public static void Test() {
Console.WriteLine("Success!");
}
}
class Program {
public static void CallMethod(string name) {
int pos = name.LastIndexOf('.');
string className = name.Substring(0, pos);
string methodName = name.Substring(pos + 1);
Type.GetType(className).GetMethod(methodName).Invoke(null, null);
}
static void Main() {
CallMethod("TestProgram.TestClass.Test");
}
}
}
这篇关于如何调用它的名字来作为参数共享功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文