Exemplo n.º 1
0
        // Evaluate is for interpretation  (and is relatively slow)
        public object Evaluate(Report rpt, Row row)
        {
            // get the results
            object[] argResults = new object[_Args.Length];
            int      i          = 0;
            bool     bUseArg    = true;
            bool     bNull      = false;

            foreach (IExpr a  in _Args)
            {
                argResults[i] = a.Evaluate(rpt, row);
                if (argResults[i] == null)
                {
                    bNull = true;
                }
                else if (argResults[i].GetType() != _ArgTypes[i])
                {
                    bUseArg = false;
                }
                i++;
            }
            // we build the arguments based on the type
            Type[] argTypes = bUseArg || bNull? _ArgTypes: Type.GetTypeArray(argResults);

            // We can definitely optimize this by caching some info TODO

            // Get ready to call the function
            Object returnVal;

            object     inst         = _Rc.Instance(rpt);
            Type       theClassType = inst.GetType();
            MethodInfo mInfo        = XmlUtil.GetMethod(theClassType, _Func, argTypes);

            if (mInfo == null)
            {
                throw new Exception(string.Format("{0} method not found in class {1}", _Func, _Cls));
            }

            returnVal = mInfo.Invoke(inst, argResults);

            return(returnVal);
        }