且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

运行到system.missingMethodException而:方法不适用于PrivateObject找到

更新时间:2023-11-21 23:20:34

根据文档(的http://msdn.microsoft.com/en-us/library/ms243710.aspx )的参数都应该作为对象数组传递。明确地传递一个对象数组似乎正常工作:

According to the docs (http://msdn.microsoft.com/en-us/library/ms243710.aspx) the arguments are supposed to be passed as an array of objects. Explicitly passing an object array appears to work correctly:

var actual = (int)privateInfo.Invoke("SampleMethod", new object[] {0});

这是自己的出现传递0导致编译器选择此重载

Passing 0 on its own appears to result in the compiler selecting this overload

Invoke(string name = "SampleMethod", System.Reflection.BindingFlags bindingFlags = Default, object[] args = {object[0]})