コード例 #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     bNull      = false;

            foreach (IExpr a  in _Args)
            {
                argResults[i] = a.Evaluate(rpt, row);
                if (argResults[i] == null)
                {
                    bNull = true;
                }
                i++;
            }
            Type[] argTypes;
            if (bNull)
            {
                // Need to put fake values in that match the types
                object[] tempResults = new object[argResults.Length];
                for (int ix = 0; ix < argResults.Length; ix++)
                {
                    tempResults[ix] =
                        argResults[ix] == null?
                        XmlUtil.GetConstFromTypeCode(_Args[ix].GetTypeCode()) :
                            argResults[ix];
                }
                argTypes = Type.GetTypeArray(tempResults);
            }
            else
            {
                argTypes = Type.GetTypeArray(argResults);
            }

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

            // Get ready to call the function
            object     returnVal;
            Type       theClassType = Type.GetType(_Cls, true, true);
            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(theClassType, argResults);

            return(returnVal);
        }