项目作者: zzzprojects

项目描述 :
C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
高级语言: C#
项目地址: git://github.com/zzzprojects/Eval-Expression.NET.git
创建时间: 2015-10-26T20:43:50Z
项目社区:https://github.com/zzzprojects/Eval-Expression.NET

开源协议:Other

下载


What’s Eval Expression.NET?

Eval Expression.NET improves performance dramatically to access public and private methods, field, property value, or create object instances overusing C# reflection.

It allows you to evaluate, Compile and Execute dynamic C# code and expression at runtime.

From simple C# math expression…

  1. int result = Eval.Execute<int>("X + Y", new { X = 1, Y = 2});

To complex code to parse.

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

Download

download

  1. PM> Install-Package Z.Expressions.Eval

* PRO Version unlocked for the current month

Eval.Execute

Evaluate and execute the code or expression.

Support:

Anonymous Class

  1. // using Z.Expressions; // Don't forget to include this.
  2. int result = Eval.Execute<int>("X + Y", new { X = 1, Y = 2});

Argument Position

  1. // using Z.Expressions; // Don't forget to include this.
  2. int result = Eval.Execute<int>("{0} + {1}", 1, 2);

Class Member

  1. // using Z.Expressions; // Don't forget to include this.
  2. dynamic expandoObject = new ExpandoObject();
  3. expandoObject.X = 1;
  4. expandoObject.Y = 2;
  5. int result = Eval.Execute<int>("X + Y", expandoObject);

Extension Methods

  1. // using Z.Expressions; // Don't forget to include this.
  2. string s = "X + Y";
  3. int result = s.Execute<int>(new { X = 1, Y = 2 });

Learn more

Eval.Compile

Compile the code or expression and return a delegate.

Support:

Custom Delegate

  1. // using Z.Expressions; // Don't forget to include this.
  2. var compiled = Eval.Compile<Func<int, int, int>>("X + Y", "X", "Y");
  3. foreach(var item in list)
  4. {
  5. int result = compiled(item.Value1, item.Value2);
  6. }

Extension Methods

  1. // using Z.Expressions; // Don't forget to include this.
  2. string s = "X + Y";
  3. var compiled = s.Compile<Func<int, int, int>>("X", "Y");
  4. foreach(var item in list)
  5. {
  6. int result = compiled(item.Value1, item.Value2);
  7. }

Learn more

What’s supported?

Eval Expression.NET supports all C# Syntax:

You can even access C# 6.0 features even if you are using C# 4.0.

  • string interpolation
  • typename
  • null conditional member access

PRO

Every month, a new monthly trial of the PRO Version is available to let you evaluate all its features without limitations.

Features PRO Version
Maximum Characters Unlimited
Commercial License Yes
Royalty-Free Yes
Support & Upgrades (1 year) Yes

Learn more about the PRO Version

  • Starting from version 2.x, there is no longer a free limited version.
  • LINQ extension method is free with EF Classic - Community

Contribute

The best way to contribute is by spreading the word about the library:

  • Blog it
  • Comment it
  • Star it
  • Share it

A HUGE THANKS for your help.

More Projects

To view all our free and paid projects, visit our website ZZZ Projects.