Created
January 30, 2013 08:35
-
-
Save jonathascosta/4671673 to your computer and use it in GitHub Desktop.
Testing Roslyn's ScriptEngine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var engine = new ScriptEngine(); | |
new[] { | |
"System", | |
"System.Core" | |
}.ToList().ForEach(assembly => engine.AddReference(assembly)); | |
new[] { | |
"System", | |
"System.Linq" | |
}.ToList().ForEach(assembly => engine.ImportNamespace(assembly)); | |
var session = engine.CreateSession(this); | |
session.Execute("var P1 = 9.8m;"); | |
session.Execute("var P2 = 6.7m;"); | |
session.Execute("var P3 = 8m;"); | |
session.Execute("var P4 = 3m;"); | |
session.Execute("decimal Min(params decimal[] args) { return args.Min(); }"); | |
session.Execute("bool Check5(params decimal[] args) { return args.Min() >= 5; }"); | |
var A = session.Execute("(P1 + P2 + P3) / 3"); | |
var B = session.Execute("Check5(P1, P2, P3)? (P1 + P2 + P3) / 3 : (P1 + P2 + P3 - Min(P1, P2, P3) + P4) / 3"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment