Reputation: 11
How to get the ParameterInfo of a function with variable number of params? The problem is when I call the method
MyFunction(object o1, out object o2);
I can get the parameterInfo of sendData but not the o1 and o2 object.
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);
}
}
..........
}
Thanks in advance for helping me.
Arnaud
Upvotes: 0
Views: 795
Reputation: 138896
'params' is just C# syntactic sugar. In fact, at metadata .NET level, there is only one parameter named "sendData" with a specific "ParamArray" attribute set.
Upvotes: 2