/// <summary> /// 最多提供16个参数,超出16个,调用些方法获取 /// </summary> /// <param name="i"></param> /// <returns></returns> protected object GetPara(int i) { if (RightVal != null) { if (paras == null) { if (RightSigelVal is object[]) { paras = (object[])RightSigelVal; } else if (RightVal != null) { paras = new object[] { RightVal }; } else { return(null); } } if (i >= paras.Length) { return(null); } CalResult cr = paras[i] as CalResult; return(cr.Results ?? cr.Result); } return(null); }
/// <summary> /// 重写集合操作 /// </summary> /// <returns></returns> protected sealed override CalResult CollectOperate() { CalResult result = new CalResult(); result.Results = new object[CLLen()]; result.ResultType = typeof(bool); for (int i = 0; i < result.Results.Length; i++) { result.Results[i] = DoSingleOperate(CLOperData(i), CROperData(i)); } return(result); }
private CalResult CallResult(BinTree <IExpressPart> calBinTree) { if (calBinTree.LeftTree == null && calBinTree.RightTree == null) { if (calBinTree.TreeNode == null) { return(new CalResult { Result = "" }); } if (calBinTree.TreeNode is CalExpress) { CalExpress ce = calBinTree.TreeNode as CalExpress; return(new CalResult { Result = ce.Value, //ResultType = Comm.GetType(ce.Express) }); } } if (calBinTree.TreeNode is IIteratorCollectionFun && this.CalCurrent.CurrentIndex != -1) { var indx = this.CalCurrent.CurrentIndex; (calBinTree.TreeNode as CalSign).OnBeginOperator += () => { this.CalCurrent.CurrentIndex = indx; }; this.CalCurrent.CurrentIndex = -1; } if (!(calBinTree.TreeNode is CalSign)) { throw new ExpressErrorException(string.Format("未能计算的表达式:{0}。", calBinTree.TreeNode)); } var calSign = (calBinTree.TreeNode as CalSign); //var time1 = DateTime.Now; CalResult leftResult = null; CalResult rightResult = null; if (calBinTree.LeftTree != null) { //如果左边是赋值的则不调取值方法 if (calBinTree.TreeNode is SetValueSign) { ((VarSign)calBinTree.LeftTree.TreeNode).IsSetValue = true; } leftResult = CallResult(calBinTree.LeftTree); } if (calBinTree.RightTree != null) { if (calBinTree.TreeNode is ConditionSign) { if (leftResult.Results != null) { throw new Exception("条件表达式左值太多"); } else { if (!(leftResult.Result is bool)) { throw new ExpressErrorException("if then的条件表达式条件必须为bool值!"); } if (leftResult.Result.ToBool()) { if (calBinTree.RightTree.TreeNode is ElseSign) { rightResult = CallResult(calBinTree.RightTree.LeftTree); } else { rightResult = CallResult(calBinTree.RightTree); } } else { if (calBinTree.RightTree.TreeNode is ElseSign) { rightResult = CallResult(calBinTree.RightTree.RightTree); } else { rightResult = new CalResult { Result = null, ResultType = typeof(bool) }; } } } } else { rightResult = CallResult(calBinTree.RightTree); } } CalSign cs = calBinTree.TreeNode as CalSign; cs.LeftVal = leftResult; cs.RightVal = rightResult; var result = cs.Operate(); //calSign.ExeTicks += DateTime.Now.Subtract(time1).TotalMilliseconds; return(result); }
/// <summary> /// 计算表达式的值 /// </summary> /// <param name="express"></param> /// <returns></returns> private CalResult CallResult1(BinTree <IExpressPart> expressBinTree) { CalResult result = null; bool flag1 = false, flag2 = false; foreach (var node in expressBinTree.BackForeach()) { //if (node is CustomFun) //也可能是变量 if (node is ICollectionResultFun) { flag1 = true; } else if (node is VarSign) { if (!CalCurrent.VarDataPool.ContainsKey((node as VarSign).SignName)) { continue; } var varvar = CalCurrent.VarDataPool[(node as VarSign).SignName]; if (varvar.Results != null) { flag1 = true; } } else if (node is ConditionSign) { flag2 = true; } if (flag1 && flag2) { break; } } if (flag1 && flag2) { if (CalCurrent.CurrentBound <= 0) { throw new Exception("未知的数组边界"); } result = new CalResult(); //需要处理 result.Results = new object[CalCurrent.CurrentBound]; for (int i = CalCurrent.CurrentBound - 1; i >= 0; i--) { this.CalCurrent.CurrentIndex = i; if (expressBinTree.TreeNode is SetValueSign) { var partResult = CallResult(expressBinTree.RightTree); result.Results[i] = partResult.Result; result.ResultType = partResult.ResultType; } else { CallResult(expressBinTree); } } if (expressBinTree.TreeNode is SetValueSign) { var key = (expressBinTree.LeftTree.TreeNode as VarSign).VarName; this.CalCurrent.VarDataPool.Add(key, result); } this.CalCurrent.CurrentIndex = -1; } else { result = CallResult(expressBinTree); } return(result); }