如何知道参数的数量和类型?
如何知道返回类型?
如何检查返回类型是否为空?
答案 0 :(得分:22)
使用MethodInfo.ReturnType
确定返回类型,使用MethodBase.GetParameters()
查找参数。 (MethodInfo
来自MethodBase
,因此,一旦您通过MethodInfo
等获得Type.GetMethod
,就可以使用ReturnType
和GetParameters()
。 )
如果方法为void
,则返回类型为typeof(void)
:
if (method.ReturnType == typeof(void))