Пример #1
0
        async void ExecuteSampleCallingMethod()
        {
            // Operation which returns integers
            ExecuteSample executeSample = new ExecuteSample();
            int           sum           = await executeSample.ReturnIntAsync();

            Console.WriteLine(sum);

            // Operation which change variable provided by calling application
            string initValue = "default Value";

            Console.WriteLine($"For Globals.SomeValue is default:{initValue}");

            string newValue = await executeSample.UseGlobalDataInScriptAsync(initValue,
                                                                             "PersonInGlobals.Name = \"Person Name changed inside script\"; SomeVariable = \"new value\";"
                                                                             + "PersonInGlobals.Items.Add(new Item(){ItemName =\"Item Name\"});");

            Console.WriteLine($"Inserted script changed value to: {newValue}");

            // Runs given code
            string code = @"int Add(int x, int y) {
                            return x+y;
                            }
                            Add(1, 4)";

            var result = await executeSample.EvaluateScriptAsync(code);

            Console.WriteLine($"Result of code is: {result.ToString()}");
        }
Пример #2
0
        private async void GlobalsButton_Click(object sender, RoutedEventArgs e)
        {
            ExecuteSample executeSample = new ExecuteSample();

            string initValue = "default Value";

            string newValue = await executeSample.UseGlobalDataInScriptAsync(initValue);

            GlobalsResultLabel.Content = $"Inserted script changed value to: {newValue}";
        }