Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top