Introduction

The Eval-Expression.NET library allows evaluating, compiling and executing C# code and expression at runtime.

It supports nearly everything including:

  • Anonymous Type
  • Extension Methods
  • Generic Type
  • Lambda Expression
  • String Interpolation

Example

Execute

// using Z.Expressions; // Don't forget to include this.

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

Compile

// using Z.Expressions; // Don't forget to include this.

string code = "Price * Quantity";
var compiled = Eval.Compile>(code);

decimal totals = 0;
foreach(var order in orders)
{
    totals += compiled(order);
}

Download

Eval-Expression.NET is a lightweight NuGet library.

download

PM> Install-Package Z.Expressions.Eval

FREE Version is limited to 50 characters. PRO Version is unlocked for the current month.

Minimum Requirement

  • .NET Framework 4.0
  • .NET Framework 4.5 (For Async Methods)