[英]How to determine if a ParameterInfo is a return parameter
How can one determine if a ParameterInfo
is a Return Parameter? 如何确定
ParameterInfo
是否为返回参数?
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). 我基于一些可能存在缺陷的假设:(1)在
MethodInfo
, ConstructorInfo
或PropertyInfo
(索引器)的成员上声明参数。 (2) ConstructorInfo
and PropertyInfo
will never have a return parameter. (2)
ConstructorInfo
和PropertyInfo
永远不会有返回参数。
您可以检查ParameterInfo.Position == -1
...但是您的相等性检查似乎同样好...尽管在某些情况下它不能正确处理覆盖或接口或泛型类型。
Assuming you're referring to out int foo
, you want parameter.IsOut
. 假设您要引用
out int foo
,则需要parameter.IsOut
。
If you want the return value, try IsRetval
, although I've never heard of that before. 如果您想要返回值,请尝试
IsRetval
,尽管我之前从未听说过。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.