[英]How to get the ParameterInfo of a function with variable number of params?
如何获取具有可变数量的参数的函数的ParameterInfo? 问题是当我调用该方法时
MyFunction(object o1, out object o2);
我可以获取sendData的parameterInfo但不能获取o1和o2对象。
protected object[] MyFunction(params object[] sendData)
{
StackTrace callStack = new StackTrace(0, false);
StackFrame callingMethodFrame = callStack.GetFrame(0);
MethodBase callingMethod = callingMethodFrame.GetMethod();
ParameterInfo[] parametersInfo = callingMethod.GetParameters();
List<object> inParams = new List<object>();
List<object> outParams = new List<object>();
for (int i = 0; i < sendData.Length; i++)
{
object value = sendData[i];
ParameterInfo info = parametersInfo[parametersInfo.Length - sendData.Length + i];
if (info.IsOut)
{
outParams.Add(value);
}
else
{
inParams.Add(value);
}
}
..........
}
在此先感谢您的帮助。
阿尔诺
'params'只是C#的语法糖。 实际上,在元数据.NET级别,只有一个名为“sendData”的参数具有特定的“ParamArray”属性集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.