如何确定ParameterInfo是否为返回参数

sma*_*man 2 .net c# reflection system.reflection parameterinfo

如何确定a ParameterInfo是否为返回参数?

我写了下面的函数,但我担心我可能会遗漏一些东西:

public bool IsReturnParameter(ParameterInfo parameter){
    var method = parameter.Member as MethodInfo;
    return method != null && parameter.Equals(method.ReturnParameter);
}
Run Code Online (Sandbox Code Playgroud)

(1)参数都宣布对成员是:我的一对夫妇的假设,这可能是有缺陷的这个基础MethodInfo,ConstructorInfoPropertyInfo(索引).(2)ConstructorInfo并且PropertyInfo永远不会有返回参数.

Jef*_*eff 7

你可以检查一下ParameterInfo.Position == -1......但是你的等式检查似乎同样好......虽然在某些情况下它不能正确处理覆盖或接口或泛型类型.