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.
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.