0

有没有更简单的方法来调用反射方法,而不是如下创建 methodInfo 和对象数组?

Assembly asm = Assembly.Load("Test");
Type t= asm.GetType("test.myclass");
object obj = Activator.CreateInstance(t);
MethodInfo mi = t.GetMethod("foo");
object[] args = { 10, 70 };
Console.WriteLine("output {0}", mi.Invoke(obj, args));
4

1 回答 1

4

使用动态关键字:

Assembly asm = Assembly.Load("Test");
Type t = asm.GetType("test.myclass");
dynamic obj = Activator.CreateInstance(t);
Console.WriteLine("output {0}", obj.Foo(10, 70));
于 2013-09-16T12:21:33.063 回答