繁体   English   中英

如何使用反射从自定义类型的方法获取返回值?

[英]how to get return value from a method of custom type using reflection?

我在类中有一个返回自定义类型的方法。 我正在使用反射来调用此方法,但无法获得响应。

注意:我无法将返回值转换为自定义类型,因为我无法在项目中引用dll。

Response = method.Invoke(instance, new[] { parameter});

Response为空。 此方法调用应返回自定义类型。

您将获得响应作为System.Object

object response = method.Invoke(instance, new[] { parameter });

有多种原因,你仍然可以得到null的响应,包括该方法本身返回null或者它是一个void的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM