@@ -12,6 +12,12 @@ public class GlobalParams
1212 public int Y ;
1313 }
1414
15+ public class SumParams
16+ {
17+ public int a ;
18+ public int b ;
19+ }
20+
1521 static void Main ( string [ ] args )
1622 {
1723 Console . WriteLine ( "EvalWithoutParameters" ) ;
@@ -32,41 +38,43 @@ static void Main(string[] args)
3238 Console . ReadLine ( ) ;
3339 }
3440
35- public static void EvalWithoutParameters ( )
41+ public static async void EvalWithoutParameters ( )
3642 {
37- var result = CSharpScript . Eval ( @"25 + 30" , ScriptOptions . Default ) ;
43+ var result = await CSharpScript . EvaluateAsync ( @"25 + 30" , ScriptOptions . Default ) ;
3844 Console . WriteLine ( "Eval: " + result ) ;
3945 }
4046
41- public static void EvalExpression ( )
47+ public static async void EvalExpression ( )
4248 {
43- var result = CSharpScript . Eval ( @"X + Y" , ScriptOptions . Default , new GlobalParams { X = 12 , Y = 25 } ) ;
49+ var result = await CSharpScript . EvaluateAsync ( @"X + Y" , ScriptOptions . Default , new GlobalParams { X = 12 , Y = 25 } ) ;
4450 Console . WriteLine ( "Eval: " + result ) ;
4551 }
4652
47- public static void ScriptCreateAndRun ( )
53+ public static async void ScriptCreateAndRun ( )
4854 {
49- var script = CSharpScript . Create ( @"var result = X + Y;" , ScriptOptions . Default ) ;
50- var state = script . Run ( new GlobalParams { X = 10 , Y = 2 } ) ;
51- var state2 = script . Run ( new GlobalParams { X = 1 , Y = 3 } ) ;
55+ var script = CSharpScript . Create ( @"var result = X + Y;" , ScriptOptions . Default , typeof ( GlobalParams ) ) ;
56+ var state = await script . RunAsync ( new GlobalParams { X = 10 , Y = 2 } ) ;
57+ var state2 = await script . RunAsync ( new GlobalParams { X = 1 , Y = 3 } ) ;
5258 Console . WriteLine ( "State variable: " + state . Variables [ "result" ] . Value ) ;
5359 Console . WriteLine ( "State2 variable: " + state2 . Variables [ "result" ] . Value ) ;
5460 }
5561
56- public static void ScriptWithNamespace ( )
62+ public static async void ScriptWithNamespace ( )
5763 {
5864 var scriptOptions = ScriptOptions . Default . AddNamespaces ( "System.IO" ) ;
5965 var script = CSharpScript . Create ( @"var result = Path.Combine(""folder"", ""file"");" , scriptOptions ) ;
60- var state = script . Run ( ) ;
66+ var state = await script . RunAsync ( ) ;
6167 Console . WriteLine ( "State variable: " + state . Variables [ "result" ] . Value ) ;
6268 }
6369
64- public static void ScriptAsDelegate ( )
70+ public static async void ScriptAsDelegate ( )
6571 {
66- var script = CSharpScript . Create ( @"int Sum(int a, int b) { return a + b;}" , ScriptOptions . Default ) ;
67- var state = script . Run ( ) ;
68- var sumFunction = state . CreateDelegate < Func < int , int , int > > ( "Sum" ) ;
69- Console . WriteLine ( "Sum function: " + sumFunction ( 2 , 22 ) ) ;
72+ var param = new SumParams { a = 2 , b = 22 } ;
73+ var script = CSharpScript . Create < int > ( @"int sum(int a, int b){return a + b;}" , ScriptOptions . Default , typeof ( SumParams ) )
74+ . ContinueWith ( "sum(a, b)" ) ;
75+ var function = script . CreateDelegate ( ) ;
76+ var result = await function ( param ) ;
77+ Console . WriteLine ( "Sum function: " + result ) ;
7078 }
7179 }
7280}
0 commit comments