Getting a return value from a methodInfo.invoke

会有一股神秘感。 提交于 2019-12-08 14:47:01

问题


How do I get a return value (int) from a methodInfo.invoke?

What makes it difficult for me is the fact that I use a string variable to call the method.

Check the example below:

if (Convert.ToBoolean(getParameterFromXML("issue", k, 1)) == true)
{
    m = k + 1;

    MethodInfo methodInfo = typeof(frmDetails).GetMethod("Issue" + m);
    methodInfo.Invoke(this, Parameters);

}

What can I do? Any help would be appreciated.


回答1:


When I read this you get the result of the method back from the Invoke-call. It is returned as an object so you need to cast it to a specific type.

var returnValue = methodInfo.Invoke(this, Parameters);


来源:https://stackoverflow.com/questions/12526614/getting-a-return-value-from-a-methodinfo-invoke

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!