草庐IT

c# - 当无法事先知道方法签名时,如何从 MethodInfo 创建委托(delegate)?

我需要一个方法,它采用一个MethodInfo实例来表示具有任意签名的非泛型静态方法,并返回一个绑定(bind)到该方法的委托(delegate),该委托(delegate)稍后可以使用Delegate.DynamicInvoke方法。我的第一个天真的尝试是这样的:usingSystem;usingSystem.Reflection;classProgram{staticvoidMain(){varmethod=CreateDelegate(typeof(Console).GetMethod("WriteLine",new[]{typeof(string)}));method.Dyna