0
好吧,这就是我想做的事:调用编译时检查方法与动态参数在C#
public static void CallStaticMethod(Type myType, String methodName, Object[] parameters)
{
MethodInfo m = myType.GetMethod(methodName); // make this compile-time safe
m.Invoke(null, parameters); // methodName method is supposed to be static
}
现在,myType.GetMethod(方式)可以在运行时失败,如果“方法名”不存在。
有什么办法可以使编译时安全吗?
(假设参数正确)
我想以某种方式调用的方法是这样的:
CallStaticMethod(()=>MyType.MyMethod(), Object[] parameters)
通知,这不起作用,因为你需要指定lambda表达式中的参数。
换句话说,我需要一个编译时安全句柄的方法。 我可以得到一个使用typeof()的类型,但它可能是一种方法?