C# Eval Function Evaluate, Compile and Execute C# code at runtime


Downloaded more than
0
times !
// From simple expression... int result = Eval.Execute<int>("X + Y", new { X = 1, Y = 2}) // To complex code. int result = Eval.Execute<int>(@" var list = new List<int>() { 1, 2, 3, 4, 5 }; var filter = list.Where(x => x < 4); return filter.Sum(x => x);");



What's Eval-Expression.NET?

Eval-Expression.NET is an Eval function. You can Evaluate, Compile and Execute C# code at runtime.



Do you offer consulting services?

Yes, you can contact us for special requests: info@zzzprojects.com



Where can I find online examples?

Online example is now available on .NET Fiddle!

Online Examples

Our achievements


2000+ Customers
75+ Countries
4000+ Requests closed
10 000 000+downloads
1 000 000+daily visitors

What we achieved over the last 4 years has grown beyond our hopes. That motivates us to continue to grow and improve all our projects. Every day, we are committed to listening to our clients to help ease the daily dev workload as much as possible.


Evaluate dynamic arithmetic/math expression

Use a complete and fast compiler which support nearly everything.

  • Operator Precedence
  • Parenthesis
  • Pow Operator (2^^3 = 8)
C# Eval - Example
// Anonymous Type
int result = Eval.Execute<int>("X + Y", new { X = 1, Y = 2} );

// Class Member
dynamic expandoObject = new ExpandoObject();
expandoObject.X = 1;
expandoObject.Y = 2;
int result = Eval.Execute<int>("X + Y", expandoObject);

// Dictionary Key
var values = new Dictionary<string, object>() { {"X", 1}, {"Y", 2} };
int result = Eval.Execute<int>("X + Y", values);

// Argument Position
int result = Eval.Execute<int>("{0} + {1}", 1, 2);

Try it

Execute dynamic string code

Improve your applications flexibility by executing code using the same C# Syntax.

  • Evaluate stored formula
  • Perform LINQ operations with string
C# Eval - Dynamic LINQ Example
int result = Eval.Execute<int>(@"
var list = new List<int>() { 1, 2, 3, 4, 5 };
return list.Where(x => x > X).Take(Y).Count();", new { X = 1, Y = 2});

Try it

Compile fast property getter/setter

Improve your code readability and maintainability with an easy-to-use and easy-to-understand API.

  • Access internal and private property
  • Avoid using slow reflection
  • Avoid making complex lambda expression
C# Eval - Fast getter & setter Example
var customer = new Customer() { Name = "ZZZ" };

var nameGetter = Eval.Compile<Func<Customer, string>>("x.Name", "x");
var name = nameGetter(customer);

Try it