Created
November 4, 2015 21:14
-
-
Save istupakov/caf8e7d3d367c027f6e4 to your computer and use it in GitHub Desktop.
Test Roslyn Scripting API. It's cool!
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
using System; | |
using System.Linq.Expressions; | |
using System.Threading.Tasks; | |
using Microsoft.CodeAnalysis.Scripting; | |
using Microsoft.CodeAnalysis.Scripting.CSharp; | |
using static System.Console; | |
namespace CSharpScriptingTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
TestScripting().Wait(); | |
} | |
static async Task TestScripting() | |
{ | |
var options = ScriptOptions.Default.WithReferences("System.Core"); | |
var expr = await CSharpScript.EvaluateAsync<Expression<Func<double, double>>>("t => t == 0 ? 34 : t + 1", options); | |
var f = expr.Compile(); | |
WriteLine($"f = {expr.ToString()}"); | |
WriteLine($"f(0) = {f(0)}"); | |
WriteLine($"f(1) = {f(1)}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment