从methodInfo.invoke获取返回值

编程入门 行业动态 更新时间:2024-10-26 08:32:32
本文介绍了从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获取返回值

本文发布于:2023-11-05 04:17:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559880.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:返回值   methodInfo   invoke

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!