How to determine if a ParameterInfo is a return parameter

548 Views Asked by At

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.

2

There are 2 best solutions below

1
On BEST ANSWER

You could check if the ParameterInfo.Position == -1...but your equality check seems equally as good...though it won't correctly handle overrides or interfaces or generic types in some cases.

3
On

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.