从methodInfo.invoke获取返回值 [英] Getting a return value from a methodInfo.invoke

查看:984
本文介绍了从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.

推荐答案

当我阅读

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获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆