如何使用.NET反射来确定方法返回类型(包括void)和参数?

时间:2010-08-11 09:22:47

标签: c# .net reflection void

如何知道参数的数量和类型?

如何知道返回类型?

如何检查返回类型是否为空?

1 个答案:

答案 0 :(得分:22)

使用MethodInfo.ReturnType确定返回类型,使用MethodBase.GetParameters()查找参数。 (MethodInfo来自MethodBase,因此,一旦您通过MethodInfo等获得Type.GetMethod,就可以使用ReturnTypeGetParameters()。 )

如果方法为void,则返回类型为typeof(void)

if (method.ReturnType == typeof(void))