Skip to content

Commit 7da3336

Browse files
committed
Script as delegate
1 parent 8eded93 commit 7da3336

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CSharpScripts/Program.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ static void Main(string[] args)
2626
Console.WriteLine("ScriptWithNamespace");
2727
ScriptWithNamespace();
2828

29+
Console.WriteLine("ScriptAsDelegate");
30+
ScriptAsDelegate();
31+
2932
Console.ReadLine();
3033
}
3134

@@ -57,5 +60,13 @@ public static void ScriptWithNamespace()
5760
var state = script.Run();
5861
Console.WriteLine("State variable: " + state.Variables["result"].Value);
5962
}
63+
64+
public static void ScriptAsDelegate()
65+
{
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));
70+
}
6071
}
6172
}
512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)