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

旧城冷巷雨未停 提交于 2019-12-21 09:36:42

问题


how to know the number and type of parameters?

how to know the return type?

how to check whether the return type is void?


回答1:


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))


来源:https://stackoverflow.com/questions/3456994/how-to-use-net-reflection-to-determine-method-return-type-including-void-and

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