public void fct_OP_12_Sep_bonjour_8dot5_CP_retInt_21_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string expr = "fct(4, \"bonjour\", 8.5)";

            evaluator.Parse(expr);

            // link function body to function call
            var funcMapper = new Func3ParamsRetIntMapper <int, string, double>();

            funcMapper.SetFunction(FctP1Int_P2String_P3Double);
            evaluator.AttachFunction("Fct", funcMapper);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value (is ExprExecFunctionCallBool override ExprExecValueBool)
            ExprExecValueInt valueInt = execResult.ExprExec as ExprExecValueInt;

            Assert.IsNotNull(execResult, "The result value should be a bool");
            Assert.AreEqual(21, valueInt.Value, "The result value should be: 18");
        }
コード例 #2
0
        /// <summary>
        /// Execute a function having 2 int parameters.
        /// </summary>
        public static void CallFunctionWith3IntParams_ret_10()
        {
            string expr = "fct(a,b,c)";

            Console.WriteLine("\n====The expression is: " + expr);

            ExpressionEval evaluator = new ExpressionEval();

            //====1/decode the expression
            evaluator.Parse(expr);

            //====2/prepare the execution, attach function
            Console.WriteLine("Attach function code to Fct() and set value to param: a=2, b=3; c=5");
            evaluator.DefineVarInt("a", 2);
            evaluator.DefineVarInt("b", 3);
            evaluator.DefineVarInt("c", 5);

            // attach the 3 params function to the function call
            Func3ParamsRetIntMapper <int, int, int> func3ParamsRetIntMapper = new Func3ParamsRetIntMapper <int, int, int>();

            func3ParamsRetIntMapper.SetFunction(FctRetInt_Int_Int_Int);
            evaluator.AttachFunction("fct", func3ParamsRetIntMapper);

            //====3/Execute the expression
            ExecResult execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution has error? (should be false): " + execResult.HasError);
            Console.WriteLine("Execution Result is an int type?: " + execResult.IsResultInt);
            Console.WriteLine("Execution Result is (should be 10): " + execResult.ResultInt);
        }