@@ -12,6 +12,12 @@ public class GlobalParams
12
12
public int Y ;
13
13
}
14
14
15
+ public class SumParams
16
+ {
17
+ public int a ;
18
+ public int b ;
19
+ }
20
+
15
21
static void Main ( string [ ] args )
16
22
{
17
23
Console . WriteLine ( "EvalWithoutParameters" ) ;
@@ -32,41 +38,43 @@ static void Main(string[] args)
32
38
Console . ReadLine ( ) ;
33
39
}
34
40
35
- public static void EvalWithoutParameters ( )
41
+ public static async void EvalWithoutParameters ( )
36
42
{
37
- var result = CSharpScript . Eval ( @"25 + 30" , ScriptOptions . Default ) ;
43
+ var result = await CSharpScript . EvaluateAsync ( @"25 + 30" , ScriptOptions . Default ) ;
38
44
Console . WriteLine ( "Eval: " + result ) ;
39
45
}
40
46
41
- public static void EvalExpression ( )
47
+ public static async void EvalExpression ( )
42
48
{
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 } ) ;
44
50
Console . WriteLine ( "Eval: " + result ) ;
45
51
}
46
52
47
- public static void ScriptCreateAndRun ( )
53
+ public static async void ScriptCreateAndRun ( )
48
54
{
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 } ) ;
52
58
Console . WriteLine ( "State variable: " + state . Variables [ "result" ] . Value ) ;
53
59
Console . WriteLine ( "State2 variable: " + state2 . Variables [ "result" ] . Value ) ;
54
60
}
55
61
56
- public static void ScriptWithNamespace ( )
62
+ public static async void ScriptWithNamespace ( )
57
63
{
58
64
var scriptOptions = ScriptOptions . Default . AddNamespaces ( "System.IO" ) ;
59
65
var script = CSharpScript . Create ( @"var result = Path.Combine(""folder"", ""file"");" , scriptOptions ) ;
60
- var state = script . Run ( ) ;
66
+ var state = await script . RunAsync ( ) ;
61
67
Console . WriteLine ( "State variable: " + state . Variables [ "result" ] . Value ) ;
62
68
}
63
69
64
- public static void ScriptAsDelegate ( )
70
+ public static async void ScriptAsDelegate ( )
65
71
{
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 ) ;
70
78
}
71
79
}
72
80
}
0 commit comments