问题
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