0

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

BobyFish
  • 11
  • 7

1 Answers1

2

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

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • Do you say it is not possible to know if o1 and o2 are out parameters because I can just use params object? – BobyFish Jun 23 '11 at 15:38
  • @BobyFish - No. I'm trying to figure out what you want to do, as actually, MyFunction(object o1, out object o2) does not even compile :-) – Simon Mourier Jun 23 '11 at 16:25
  • Oh you're fine ! I've understood where is my problem. Thanks for your answers Simon. – BobyFish Jun 24 '11 at 07:25