// 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; foreach (IExpr a in _Args) { argResults[i] = a.Evaluate(rpt, row); if (argResults[i] != null && argResults[i].GetType() != _ArgTypes[i]) { bUseArg = false; } i++; } // we build the arguments based on the type Type[] argTypes = bUseArg? _ArgTypes: Type.GetTypeArray(argResults); // We can definitely optimize this by caching some info TODO // Get ready to call the function Object returnVal; Type theClassType = _Cm[_Cls]; 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); }
// 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); }
// Evaluate is for interpretation (and is relatively slow) public object Evaluate(Report rpt, Row row) { if (rpt == null || rpt.CodeInstance == null) { return(null); } // 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++; } 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 = rpt.CodeInstance; Type theClassType = inst.GetType(); MethodInfo mInfo = XmlUtil.GetMethod(theClassType, _Func, argTypes); if (mInfo == null) { throw new Exception(string.Format("{0} method not found in code", _Func)); } returnVal = mInfo.Invoke(inst, argResults); return(returnVal); }