Esempio n. 1
0
        private void ScriptInFile()
        {
            Console.WriteLine("Running script from file...");

            var script = new Script();
            script.InitializeFromFile(@"..\..\..\Scripts\script1.py");

            // no params call
            Console.WriteLine(script.Execute<string>("script1class", "Hello"));

            // single param call
            Console.WriteLine(script.Execute<string>("script1class", "HelloWithName", "Paulo"));

            // pass instance of complex type
            var person = new Person { Name = "Paulo Mouat", Address = "Boston" };
            Console.WriteLine(script.Execute<string>("script1class", "HelloWithPerson", person));

            // duck typing
            var hasNameLikePerson = new HasNameLikePerson { Name = "HAL", Model = 9000 };
            Console.WriteLine(script.Execute<string>("script1class", "HelloWithPerson", hasNameLikePerson));

            // change field in passed type
            var changeState = new Person { Name = "Paulo Mouat", Address = "Boston" };
            Console.WriteLine("Original state: " + changeState);
            script.Execute<string>("script1class", "ChangeAddress", changeState);
            Console.WriteLine("New state: " + changeState);
            Console.WriteLine();
        }