/// <summary> /// This method is processing vars. /// </summary> /// <param name="sParam">String with @vars.</param> /// <param name="fFunc">The instance of Func class, which is currently running.</param> /// <returns>String, where all @vars are changed to their values.</returns> public string processVars(string sParam, Func fFunc) { string sRet = ""; string[] splitParam = sParam.Split(' '); foreach (string s in splitParam) { if (s.IndexOf('@') == 0) // if local var { sRet += fFunc.getVar(s) + " "; } else if (s.IndexOf('&') == 0) //if global var { sRet += fFunc.getGlVar(s) + " "; } else sRet += s + " "; } sRet = sRet.Trim(); return sRet; }
/// <summary> /// This method process some logical sequence and returns result - is it true or false. /// </summary> /// <param name="sParam">Some sequence</param> /// <param name="fFunc">Func class instance</param> /// <returns>Is this seq. true or false.</returns> public bool processLogicalSeq(string sParam, Func fFunc) { bool answer = false; string[] logicalMarks = new string[6] { "<=", ">=", "==", "!=", "<", ">"}; string[] sParams = sParam.Split(logicalMarks, StringSplitOptions.None); if (sParams.Length != 1) { string usedLogic = sParam.Substring(sParams[0].Length, sParam.Length - sParams[0].Length - sParams[1].Length).Trim(); sParams[0] = processComplicatedSeq(processVars(sParams[0].Trim(), fFunc)); sParams[1] = processComplicatedSeq(processVars(sParams[1].Trim(), fFunc)); if (!bStartBreaking) { Base a = new Base(); a.SetUntyped(sParams[0]); Base b = new Base(); b.SetUntyped(sParams[1]); switch (usedLogic) { case "<": answer = (a < b); break; case ">": answer = (a > b); break; case "<=": answer = (a <= b); break; case ">=": answer = (a >= b); break; case "!=": answer = (a != b); break; case "==": answer = (a == b); break; } } else switch (sParams[0][0]) { case '@': try { answer = Convert.ToBoolean(fFunc.getVar(sParams[0].Trim())); } catch { answer = false; } break; case '&': try { answer = Convert.ToBoolean(fFunc.getGlVar(sParams[0].Trim())); } catch { answer = false; } break; default: break; } } return answer; }