public void UntypedDelegateForPythonFunction()
        {
            Dictionary <string, object> context = new Dictionary <string, object>();

            context.Add("user", "alex");
            context.Add("age", 26);

            List <string> parameters = new List <string>(context.Keys);
            List <object> values     = new List <object>(context.Values);

            PythonEngine engine = new PythonEngine();

            engine.Execute(
                GenerateFunction("func", parameters.ToArray(), "return user + ' is ' + str(age) + ' years old'"));

            PythonFunction func1 = engine.EvaluateAs <PythonFunction>("func");

            UntypedDelegate func1Delegate = delegate(object[] param)

            {
                return(func1.Call(param));
            };

            object result1 = func1Delegate(values.ToArray());

            Assert.AreEqual("alex is 26 years old", result1);
        }
        public void GeneratingPythonFunction()
        {
            Dictionary <string, object> context = new Dictionary <string, object>();

            context.Add("user", "alex");
            context.Add("age", 26);

            List <string> parameters = new List <string>(context.Keys);
            List <object> values     = new List <object>(context.Values);

            PythonEngine engine = new PythonEngine();

            engine.Execute(
                GenerateFunction("func", parameters.ToArray(), "return user + ' is ' + str(age) + ' years old'"));

            PythonFunction func1 = engine.EvaluateAs <PythonFunction>("func");

            engine.Execute(
                GenerateFunction("func", parameters.ToArray(),
                                 "return user + ' is ' + str(age+1) + ' years old next year'"));

            PythonFunction func2 = engine.EvaluateAs <PythonFunction>("func");

            object result1 = func1.Call(values.ToArray());

            Assert.AreEqual("alex is 26 years old", result1);

            object result2 = func2.Call(values.ToArray());

            Assert.AreEqual("alex is 27 years old next year", result2);
        }