How to use .NET reflection to determine method return type (including void) and parameters?

好久不见. 提交于 2019-12-04 03:40:36
Jon Skeet

Use MethodInfo.ReturnType to determine the return type, and MethodBase.GetParameters() to find out about the parameters. (MethodInfo derives from MethodBase, so once you've got the MethodInfo via Type.GetMethod etc, you can use both ReturnType and GetParameters().)

If the method is void, the return type will be typeof(void):

if (method.ReturnType == typeof(void))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!