How can one determine if a ParameterInfo
is a Return Parameter?
I wrote the function below, but I'm concerned that I may be missing something:
public bool IsReturnParameter(ParameterInfo parameter){
var method = parameter.Member as MethodInfo;
return method != null && parameter.Equals(method.ReturnParameter);
}
I am basing this on a couple assumptions, which may be flawed: (1) Parameters are declared on members that are MethodInfo
, ConstructorInfo
or PropertyInfo
(indexers). (2) ConstructorInfo
and PropertyInfo
will never have a return parameter.
您可以检查ParameterInfo.Position == -1
...但是您的相等性检查似乎同样好...尽管在某些情况下它不能正确处理覆盖或接口或泛型类型。
Assuming you're referring to out int foo
, you want parameter.IsOut
.
If you want the return value, try IsRetval
, although I've never heard of that before.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.