Exemple #1
0
        private bool TryBuildVarArgArray(MethodBase method, object[] args, object[] convertedArgs)
        {
            Type[] paramTypeArray = method.GetParamsTypeArray();
            int last = paramTypeArray.Length - 1;
            object val;
            Array varArr;

            if (args.Length < convertedArgs.Length)
            {
                varArr = (Array)Activator.CreateInstance(paramTypeArray[last], 0);
            }
            else if (args.Length > convertedArgs.Length)
            {
                varArr = (Array)Activator.CreateInstance(paramTypeArray[last], args.Length - paramTypeArray.Length + 1);
                for (int i = 0; i < varArr.Length; i++)
                {
                    if (!TryConvertOneArgument(args[i + paramTypeArray.Length - 1], method.GetVarArgElementType(), out val))
                        return false;
                    else
                        varArr.SetValue(val, i);
                }
            }
            else
            {
                varArr = (Array)Activator.CreateInstance(paramTypeArray[last], 1);
                if (!TryConvertOneArgument(args[last], method.GetVarArgElementType(), out val))
                    return false;
                else
                    varArr.SetValue(val, 0);
            }

            convertedArgs[last] = varArr;
            return true;
        }
Exemple #2
0
 private bool TryConvertArgumentArray(MethodBase method, object[] args, object[] convertedArgs, int length)
 {
     Type[] paramTypeArray = method.GetParamsTypeArray();
     for (int i = 0; i < length; i++)
     {
         if (!TryConvertOneArgument(args[i], paramTypeArray[i], out convertedArgs[i]))
             return false;
     }
     return true;
 }