本文介绍了从methodInfo.invoke获取返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从methodInfo.invoke获取返回值(int)?
让我感到困难的是,我使用字符串变量来调用该方法.
What makes it difficult for me is the fact that I use a string variable to call the method.
检查以下示例:
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.
推荐答案当我阅读这,您可以从Invoke调用中获取方法的结果.它作为对象返回,因此您需要将其强制转换为特定类型.
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 = (int) methodInfo.Invoke(this, Parameters);更多推荐
从methodInfo.invoke获取返回值
发布评论