反射,从方法获取返回值 [英] Reflection, Get return value from a method

查看:48
本文介绍了反射,从方法获取返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何执行一种方法并从Reflection中获取返回值.

How can we exacute a method and get the return value from Reflection.

Type serviceType = Type.GetType("class", true);
var service = Activator.CreateInstance(serviceType);
serviceType.InvokeMember("GetAll", BindingFlags.InvokeMethod, Type.DefaultBinder, service, null);

推荐答案

将InvokeMember结果转换为方法调用实际返回的类型.

cast the InvokeMember result to the type actually returned by the method call.

这篇关于反射,从方法获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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