简体   繁体   English

如何确定ParameterInfo是否为返回参数

[英]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)在MethodInfoConstructorInfoPropertyInfo (索引器)的成员上声明参数。 (2) ConstructorInfo and PropertyInfo will never have a return parameter. (2) ConstructorInfoPropertyInfo永远不会有返回参数。

您可以检查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.

相关问题 如何确定ParameterInfo是否是泛型类型? - How to determine if ParameterInfo is of generic type? 从Web API控制器方法中的ParameterInfo确定参数位置 - Determine Parameter Location From ParameterInfo In Web API Controller Method ParameterInfo是一个扩展方法参数? - ParameterInfo is a extension method parameter? 获取ParameterInfo参数的参考 - Get reference of ParameterInfo parameter C#反射:如何确定ParameterInfo是否是在父类上定义的泛型类型 - C# Reflection: How to determine if ParameterInfo is a generic type defined on parent class 给定参数的ParameterInfo时,如何检查服务方法的参数类型是否为输出类型? - How do I check if a service method's parameter type is an output type given the parameter's ParameterInfo? 如何判断ParameterInfo类型是否为集合? - How to tell if ParameterInfo type is a collection? 确定Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo是否为变量? - Determine if Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo is a Variable? 如何从反射中的 ParameterInfo[] 获得真正的价值 - How to get real value from the ParameterInfo[] in Reflection 如何获取具有可变数量的参数的函数的ParameterInfo? - How to get the ParameterInfo of a function with variable number of params?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM