Beispiel #1
0
 private object EvalFunction(ICallable callee, object[] args)
 {
     if (callee is IntrinsicFunction)
     {
         IntrinsicFunction ifun   = (IntrinsicFunction)callee;
         MethodBase        mmodel = ifun.MethodModel;
         if (mmodel != null)
         {
             if (mmodel.IsStatic)
             {
                 return(mmodel.ConvertArgumentsAndInvoke(null, args));
             }
             else
             {
                 object[] eargs = new object[args.Length - 1];
                 Array.Copy(args, 1, eargs, 0, eargs.Length);
                 return(mmodel.ConvertArgumentsAndInvoke(args[0], eargs));
             }
         }
         else
         {
             throw new NotImplementedException();
         }
     }
     else if (callee is MSILFunctionRef)
     {
         MSILFunctionRef mfr = (MSILFunctionRef)callee;
         return(InterpreteInternal(mfr.Method, args));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
        /// <summary>
        /// This extension method invokes a given method with a given argument list. If the method is non-static, the "this" argument is expected to be the first value within the args parameter.
        /// </summary>
        /// <param name="mb">the method to be invoked</param>
        /// <param name="args">the argument list</param>
        /// <returns>the return value of the invoked method, null if the method does not return any value.</returns>
        public static object Invoke(this MethodBase mb, params object[] args)
        {
            object result;

            if (mb.IsStatic || mb is ConstructorInfo)
            {
                result = mb.ConvertArgumentsAndInvoke(null, args);
            }
            else
            {
                object[] paramArgs = args.Skip(1).ToArray();
                result = mb.ConvertArgumentsAndInvoke(args[0], paramArgs);
                Array.Copy(paramArgs, 0, args, 1, paramArgs.Length);
            }
            return(result);
        }
Beispiel #3
0
 public object EvalFunction(FunctionCall funcref, object[] args, TypeDescriptor resultType)
 {
     if (funcref.Callee is IntrinsicFunction)
     {
         IntrinsicFunction ifun   = (IntrinsicFunction)funcref.Callee;
         MethodBase        mmodel = ifun.MethodModel;
         if (mmodel != null && mmodel.IsStatic)
         {
             object result = mmodel.ConvertArgumentsAndInvoke(null, args);
             return(result);
         }
     }
     return(DoEvalFunction(funcref, args));
 }