Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 686 Bytes

README.md

File metadata and controls

24 lines (20 loc) · 686 Bytes

CSharpEval NuGet version

Compile and execute C# code at program runtime

Examples

Simple math expression

var result = CSharpEval.Execute<int>("A + B", new { A = 2, B = 3});

Linq sample

var result = CSharpEval.Execute<int>(@"
    var list = new List<int>() { 1, 2, 3, 4, 5 };
    return list.Where(x => x < K).Sum(x => x);
", new { K = 5 });

Adding references

CSharpEval.Execute("Console.WriteLine(A)", 
    new { A = ExternalLib.SomeEnum.Sample }, 
    new[] { Assembly.GetAssembly(typeof(ExternalLib.SomeEnum)) });