如何知道参数的个数和类型?
如何知道返回类型?
如何检查返回类型是否为void?
用于MethodInfo.ReturnType
确定返回类型,并MethodBase.GetParameters()
找出参数。(MethodInfo
派生自MethodBase
,因此一旦您获得了MethodInfo
viaType.GetMethod
等,您就可以同时使用ReturnType
和GetParameters()
。)
如果方法是void
,返回类型将是typeof(void)
:
if (method.ReturnType == typeof(void))