Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 916 Bytes

README.md

File metadata and controls

39 lines (30 loc) · 916 Bytes

C# Eval

C# Eval is a library for running and debugging your code at runtime


Examples

Basic evaluation

// Create a basic evaluation context with no references or usings
BasicCSharpEvaluator evaluator = new BasicCSharpEvaluator(Enumerable.Empty<Assembly>(), Enumerable.Empty<string>());

evaluator.Eval("int x = 47;");
evaluator.Eval("int y = 3;");

Console.WriteLine(evaluator.Eval("(x + y) / 2").Result); // Prints 25

Importing a library and using

Assembly[] references = new Assembly[] { typeof(System.Console).Assembly };
string[] usings = new string[] { "System" };

// Create a basic evaluation context with a reference to the System library and a using System
BasicCSharpEvaluator evaluator = new BasicCSharpEvaluator(references, usings);

evaluator.Eval("Console.WriteLine(\"Hello From Eval\")");