Z.Expressions.Eval 6.1.10

There is a newer version of this package available.
See the version list below for details.
dotnet add package Z.Expressions.Eval --version 6.1.10                
NuGet\Install-Package Z.Expressions.Eval -Version 6.1.10                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Z.Expressions.Eval" Version="6.1.10" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Z.Expressions.Eval --version 6.1.10                
#r "nuget: Z.Expressions.Eval, 6.1.10"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Z.Expressions.Eval as a Cake Addin
#addin nuget:?package=Z.Expressions.Eval&version=6.1.10

// Install Z.Expressions.Eval as a Cake Tool
#tool nuget:?package=Z.Expressions.Eval&version=6.1.10                

Z.Expressions.Eval: C# Eval Expression

Z.Expressions.Eval is a robust NuGet package that enables .NET developers to evaluate, compile, and execute dynamic C# expressions. By interpreting and processing strings as executable code, this package empowers developers to craft highly adaptable and customizable applications.

It has the capability to handle an extensive range of mathematical operations, string manipulations, boolean logic, and it can even interact with .NET objects and classes.

The principal advantage of Z.Expressions.Eval lies in its ability to provide enhanced flexibility by facilitating runtime execution and manipulation of C# expressions. This feature is particularly beneficial in scenarios where business rules are subject to frequent changes or need to be configurable.

Having earned the trust and endorsement of over 5000 customers worldwide, C# Eval Expression is a highly regarded library that has become an essential tool for a wide variety of projects.

Resources:

  • Official Website: Visit for comprehensive information, updates, tutorials, and more. Learn how Z.Expressions.Eval can significantly enhance your application's capabilities.
  • Contact Us: Have a question or need assistance? Don't hesitate to reach out. We're here to help you get the most out of C# Eval Expression.
  • GitHub Issues: Encountered an issue or have a feature request? Let us know on GitHub. Your feedback helps us make C# Eval Expression even better.

Supported .NET Versions

Z.Expressions.Eval exhibits broad compatibility with a variety of .NET versions. Starting from .NET Framework 4.5 and .NET Core 2.0, it extends support to the most recent versions of .NET.

To take full advantage of the enhancements in newer .NET versions, we highly recommend upgrading to the latest package version of Z.Expressions.Eval.

Main Features

Z.Expressions.Eval provides a set of powerful features designed to simplify dynamic C# expression evaluation and execution. Here are some of the key features:

  • Eval.Execute: Allows you to evaluate and execute a string as a C# expression at runtime. This feature can handle a wide variety of mathematical operations, string manipulations, boolean logic, and even work with .NET objects and classes.
  • Eval.Compile: Offers the ability to compile a string as a C# expression at runtime, reducing the overhead of repeated evaluations. This feature is especially useful when working with expressions that need to be executed multiple times.
  • LINQ Dynamic: Provides the power to execute LINQ expressions dynamically. This feature opens up new possibilities for creating highly flexible and configurable queries.

For a more detailed explanation and examples of each operation, please refer to the official documentation page.

Getting Started

To get a feel for Z.Expressions.Eval, here is a simple example:

using Z.Expressions;

public class Program
{
    public static void Main()
    {
        var result = Eval.Execute<int>("X*Y", new { X = 10, Y = 20 });
        Console.WriteLine(result); // Outputs: 200
    }
}

In the above example, the "X*Y" string expression is evaluated dynamically at runtime with the values of X and Y provided in an anonymous object. The result is then printed to the console.

Want to explore the library further? We offer an extensive collection of online examples showcasing the various functionalities and capabilities of C# Eval Expression:

These examples are specifically designed to impart practical understanding of C# Eval Expression, demonstrating its potent features and adaptable options in a variety of scenarios.

Advanced Usage

Instance Context

Z.Expressions.Eval allows more advanced scenarios, such as operating in a specific context, using variables, and more. Here's an example illustrating the use of instance context:

// CREATE a new instance of EvalContext
var context = new EvalContext();

// USE the `Execute` method from the context created
var list1 = context.Execute<List<int>>("new List<int>() { 1, 2, 3 };");

In this example, we first create a new instance of EvalContext. Then, we use the Execute method from the created context to evaluate and execute a string as a C# expression, which instantiates a new List<int>.

Try it online

Register Type

The RegisterType method allows you to register all types provided for the context. The method also registers extension methods from those types but does not register other static members. For instance, if you register the type "Z.MyNamespace.MyClass", you can subsequently create an expression such as "new MyClass()" or any extension methods from this type.

In the following example, we'll register the types MyClassHelper and MyExtensions to include their extension methods. We'll first demonstrate how to use our class and extension methods in an arithmetic operation. We'll then show how to utilize the IsRegisteredType and UnregisterType methods with MyClassHelper to verify if the type is currently registered and to unregister it.

using System;
using System.Collections.Generic;
using Z.Expressions;

public class Program
{
	public static void Main()
	{
		// Global Context: EvalManager.DefaultContext.RegisterType(typeof(Helper));
		
		var context = new EvalContext();
		context.RegisterType(typeof(MyClassHelper));
		context.RegisterType(typeof(MyExtensions));
		
		var r1 = context.Execute<int>("new MyClassHelper().MyClassHelperID + 2.AddMe(3)"); // return 6
		Console.WriteLine("1 - Result: " + r1);
		
		// Check if the type `MyClassHelper` is registered
		var r2 = context.IsRegisteredType(typeof(MyClassHelper)); // return true
		Console.WriteLine("2 - Result: " + r2);
		
		// Unregister the type `MyClassHelper`
		context.UnregisterType(typeof(MyClassHelper));
		
		// Check the type `MyClassHelper` has been succesfully unregistered
		var r3 = context.IsRegisteredType(typeof(MyClassHelper)); // return false
		Console.WriteLine("3 - Result: " + r3);
	}
	
	public class MyClassHelper
	{
		public int MyClassHelperID { get; set; } = 1;
	}
}

public static class MyExtensions
{	
	public static int AddMe(this int x, int y)
	{
		return x + y;
	}
}

Try it online

Use Options

The SafeMode option allows you to set the context to only allow the usage of registered members and types within expressions. In essence, it enables a secure execution environment for user input, restricting usage to only what you explicitly permit. By default, SafeMode is set to false.

In this example, we demonstrate how SafeMode method. Please ensure to thoroughly understand the SafeMode documentation if you intend to use this option.

// Global Context: EvalManager.DefaultContext.SafeMode = true;

var context = new EvalContext();

context.SafeMode = true;
context.UnregisterAll();

try
{
	var fail = context.Execute("Math.Min(1, 2)");
	Console.WriteLine(fail);
}
catch(Exception ex)
{
	Console.WriteLine("1 - Exception: " + ex.Message);
}

// try again by registering "System.Math" member
context.RegisterMember(typeof(System.Math));
var r2 = context.Execute("Math.Min(1, 2)");
Console.WriteLine("2 - Result: " + r2);

Try it online

Release Notes

For a thorough record of enhancements, bug fixes, and upgrades in each iteration of C# Eval Expression, we recommend referring to the official Release Notes located in our GitHub repository.

The Release Notes offer essential insights about each version, detailing new features, addressing resolved issues, and mentioning any breaking changes (if applicable). We strongly advise reviewing these notes prior to upgrading to a newer version. This practice not only ensures you leverage the full potential of the newly introduced features but also helps prevent unforeseen complications.

License

C# Eval Expression utilizes a paid licensing model. To acquire a license, please visit our official Pricing Page on the Eval Expression website.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (14)

Showing the top 5 NuGet packages that depend on Z.Expressions.Eval:

Package Downloads
Z.EntityFramework.Plus.EFCore

Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more **IMPORTANT** - For EF Core 9.x, use the latest EF Plus v9.x version - For EF Core 8.x, use the latest EF Plus v8.x version - For EF Core 7.x, use the latest EF Plus v7.x version - For EF Core 6.x, use the latest EF Plus v6.x version - For EF Core 5.x, use the latest EF Plus v5.x version - For EF Core 3.x, use the latest EF Plus v3.x version - For EF Core 2.x, use the latest EF Plus v2.x version

Z.EntityFramework.Plus.EF6

Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more

Z.EntityFramework.Classic

Entity Framework Classic is an EF6 fork with performance enhancement, new features, and .NET Core support. This package is FREE (Community Version) Some features are Prime (Enterprise Version) Prime features can be disabled with "EntityFrameworkManager.IsCommunity = true;"

Z.EntityFramework.Plus.EF5

Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more EF Core Package: https://www.nuget.org/packages/Z.EntityFramework.Plus.EFCore/ EF6 Package: https://www.nuget.org/packages/Z.EntityFramework.Plus.EF6/

DianFengBaseLib.Infrastructure

配合DDD使用

GitHub repositories (6)

Showing the top 5 popular GitHub repositories that depend on Z.Expressions.Eval:

Repository Stars
zzzprojects/EntityFramework-Plus
Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more
zzzprojects/EntityFramework.DynamicFilters
Global filtering for Entity Framework.
zzzprojects/Eval-Expression.NET
C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
zzzprojects/EntityFramework-Effort
Entity Framework Effort is a powerful tool that enables a convenient way to create automated tests for Entity Framework based applications.
DigitalPlatform/dp2
Integrated Library System / 图书馆集成系统
Version Downloads Last updated
6.2.2 15,711 11/12/2024
6.2.2-beta2 71 11/14/2024
6.2.2-beta1 68 11/14/2024
6.2.1 69,128 10/22/2024
6.2.0 181,008 9/23/2024
6.2.0-beta1 89 10/2/2024
6.1.10 167,175 8/27/2024
6.1.9 146,328 8/12/2024
6.1.8 145,158 7/22/2024
6.1.7 343,858 6/18/2024
6.1.6 117,340 6/3/2024
6.1.2 629,055 3/11/2024
6.1.1 165,499 2/27/2024
6.1.0 392,487 2/13/2024
6.0.6 523,852 1/15/2024
6.0.5 254,484 12/18/2023
6.0.4 3,262 12/11/2023
6.0.3 120,049 12/5/2023
6.0.2 108,281 11/28/2023
6.0.1 1,161 11/28/2023
6.0.0 216,726 11/15/2023
5.0.12 3,150 11/7/2023
5.0.11 391,129 10/17/2023
5.0.10 260,985 9/26/2023
5.0.9 235,173 9/11/2023
5.0.8 230,558 8/15/2023
5.0.7 596,240 7/11/2023
5.0.6 303,838 6/12/2023
5.0.5 7,754 5/30/2023
5.0.4 453,251 5/16/2023
5.0.3 357,214 4/17/2023
5.0.2 337,693 3/20/2023
5.0.1 499,717 2/20/2023
5.0.0 811,922 1/17/2023
4.0.92 413,204 12/20/2022
4.0.91 375,086 12/5/2022
4.0.90 577,049 11/14/2022
4.0.89 952,141 10/10/2022
4.0.88 1,181,898 9/12/2022
4.0.87 787,949 8/16/2022
4.0.86 1,003,352 7/19/2022
4.0.85 775,350 6/14/2022
4.0.84 139,752 6/7/2022
4.0.83 24,268 5/26/2022
4.0.82 437,738 5/24/2022
4.0.81 208,296 5/17/2022
4.0.80 198,953 5/10/2022
4.0.79 787,060 4/12/2022
4.0.78 493,936 3/30/2022
4.0.77 736,416 3/15/2022
4.0.76 299,568 3/1/2022
4.0.75 146,513 2/22/2022
4.0.74 291,896 2/14/2022
4.0.73 128,583 2/8/2022
4.0.72 17,992 2/1/2022
4.0.71 568,791 1/18/2022
4.0.70 285,453 1/11/2022
4.0.69 1,657,448 12/30/2021
4.0.68 14,615 12/15/2021
4.0.67 265,931 12/14/2021
4.0.66 3,695 12/7/2021
4.0.65 2,939 11/30/2021
4.0.64 329,707 11/24/2021
4.0.63 340,168 11/17/2021
4.0.62 294,530 11/9/2021
4.0.61 2,942 11/4/2021
4.0.60 302,811 10/27/2021
4.0.59 145,339 10/20/2021
4.0.58 89,459 10/13/2021
4.0.57 2,642 10/12/2021
4.0.56 6,768 10/6/2021
4.0.55 6,127 9/29/2021
4.0.54 556,327 9/15/2021
4.0.53 109,667 9/8/2021
4.0.52 202,964 9/1/2021
4.0.51 88,193 8/25/2021
4.0.50 164,605 8/17/2021
4.0.49 176,798 8/4/2021
4.0.48 458,750 7/28/2021
4.0.47 196,302 7/20/2021
4.0.46 232,135 7/13/2021
4.0.45 522,698 6/16/2021
4.0.44 75,198 6/14/2021
4.0.43 481,345 5/12/2021
4.0.42 135,024 5/3/2021
4.0.41 214,750 4/26/2021
4.0.40 2,416 4/22/2021
4.0.39 118,228 4/19/2021
4.0.38 154,267 4/7/2021
4.0.37 265,230 3/24/2021
4.0.37-beta1 1,638 4/1/2021
4.0.36 143,260 3/16/2021
4.0.35 38,433 3/15/2021
4.0.34 208,180 3/10/2021
4.0.33 11,479 2/23/2021
4.0.32 581,159 2/16/2021
4.0.31 156,102 2/10/2021
4.0.30 162,109 2/2/2021
4.0.29 308,945 1/13/2021
4.0.28 575,186 12/14/2020
4.0.27 67,654 12/8/2020
4.0.26 104,478 12/1/2020
4.0.25 71,959 11/27/2020
4.0.24 205,670 11/11/2020
4.0.23 216,016 10/30/2020
4.0.22 730,561 10/11/2020
4.0.21 52,131 10/7/2020
4.0.20 3,264 10/5/2020
4.0.19 102,910 9/30/2020
4.0.18 4,333 9/29/2020
4.0.17 30,041 9/24/2020
4.0.16 316,638 9/14/2020
4.0.15 228,628 8/31/2020
4.0.14 7,179 8/25/2020
4.0.13 5,251 8/17/2020
4.0.12 229,829 8/11/2020
4.0.11 100,278 8/3/2020
4.0.10 18,477 7/28/2020
4.0.9 149,630 7/22/2020
4.0.8 3,217 7/19/2020
4.0.7 2,159 7/19/2020
4.0.6 256,082 7/14/2020
4.0.5 2,246 7/13/2020
4.0.4 90,097 7/12/2020
4.0.3 12,492 7/5/2020
4.0.2 8,608 6/30/2020
4.0.1 678,274 6/14/2020
4.0.0 79,627 6/1/2020
3.1.12 17,103 5/25/2020
3.1.11 672,854 5/14/2020
3.1.10 464,891 4/14/2020
3.1.9 49,259 4/3/2020
3.1.8 616,619 3/16/2020
3.1.7 5,918 3/10/2020
3.1.6 555,264 2/21/2020
3.1.5 305,609 2/18/2020
3.1.4 19,614 2/15/2020
3.1.3 56,694 2/7/2020
3.1.2 474,938 1/27/2020
3.1.1 4,155 1/23/2020
3.1.0 8,303 1/14/2020
3.0.14 6,267 1/13/2020
3.0.13 26,220 1/9/2020
3.0.12 5,502 1/3/2020
3.0.11 10,105 12/19/2019
3.0.10 3,808 12/17/2019
3.0.9 514,771 12/16/2019
3.0.8 5,834 12/11/2019
3.0.7 311,169 11/25/2019
3.0.6 23,663 11/18/2019
3.0.5 3,839 11/14/2019
3.0.4 7,773 11/12/2019
3.0.3 601,875 10/30/2019
3.0.2 2,210 10/30/2019
3.0.1 12,966 10/29/2019
3.0.0 2,623 10/29/2019
2.9.57 12,297 10/16/2019
2.9.56 2,648 10/10/2019
2.9.55 6,011 10/2/2019
2.9.54 16,269 9/22/2019
2.9.52 3,030 9/6/2019
2.9.51 2,273 9/5/2019
2.9.50 2,246 9/4/2019
2.9.49 2,710 8/29/2019
2.9.48 8,366 8/24/2019
2.9.47 2,306 8/24/2019
2.9.46 39,859 8/15/2019
2.9.45 160,969 7/28/2019
2.9.44 3,078 7/15/2019
2.9.43 3,524 7/9/2019
2.9.42 6,238 7/4/2019
2.9.41 2,441 7/3/2019
2.9.40 2,385 7/1/2019
2.9.39 16,192 6/29/2019
2.9.38 2,266 6/25/2019
2.9.37 2,787 6/12/2019
2.9.36 2,417 6/7/2019
2.9.35 2,269 6/4/2019
2.9.34 2,568 5/31/2019
2.9.33 4,271 5/31/2019
2.9.32 4,444 5/23/2019
2.9.31 36,567 5/20/2019
2.9.30 2,328 5/17/2019
2.9.29 2,381 5/9/2019
2.9.28 2,214 5/9/2019
2.9.27 4,366 5/5/2019
2.9.26 2,238 5/3/2019
2.9.25 7,189 4/30/2019
2.9.24 2,970 4/18/2019
2.9.22 2,414 4/16/2019
2.9.21 10,145 4/7/2019
2.9.20 32,376 3/30/2019
2.9.19 2,509 3/27/2019
2.9.18 2,337 3/26/2019
2.9.17 2,531 3/21/2019
2.9.16 2,244 3/20/2019
2.9.15 2,274 3/20/2019
2.9.14 2,419 3/16/2019
2.9.13 2,334 3/16/2019
2.9.12 92,393 2/27/2019
2.9.11 2,619 2/20/2019
2.9.10 2,341 2/18/2019
2.9.9 2,275 2/16/2019
2.9.8 2,969 2/13/2019
2.9.7 2,701 2/8/2019
2.9.6 6,106 1/30/2019
2.9.5 8,460 1/13/2019
2.9.4 5,959 12/30/2018
2.9.3 2,887 12/13/2018
2.9.2 2,471 12/13/2018
2.9.1 2,583 12/12/2018
2.9.0 2,403 12/12/2018
2.8.9 2,966 12/11/2018
2.8.8 69,999 11/29/2018
2.8.7 2,924 11/28/2018
2.8.6 2,433 11/27/2018
2.8.5 3,672 11/20/2018
2.8.4 2,542 11/18/2018
2.8.3 2,488 11/17/2018
2.8.2 2,493 11/17/2018
2.8.1 2,683 11/14/2018
2.8.0 2,427 11/14/2018
2.7.13 4,959 10/29/2018
2.7.12 9,532 10/28/2018
2.7.11 2,547 10/23/2018
2.7.10 4,259 10/17/2018
2.7.9 5,014 10/7/2018
2.7.8 5,533 9/29/2018
2.7.7 5,366 8/31/2018
2.7.6 6,046 8/30/2018
2.7.5 2,881 8/18/2018
2.7.4 5,345 8/16/2018
2.7.3 3,437 8/16/2018
2.7.2 4,757 7/31/2018
2.7.1 3,201 7/19/2018
2.7.0 3,193 7/5/2018
2.6.5 2,997 6/29/2018
2.6.4 3,695 5/31/2018
2.6.3 3,957 5/2/2018
2.6.2 3,034 4/30/2018
2.6.1 3,783 3/30/2018
2.6.0 2,932 3/26/2018
2.5.0 2,938 3/20/2018
2.4.21 2,763 3/20/2018
2.4.20 2,832 3/16/2018
2.4.19 3,335 2/27/2018
2.4.18 3,336 2/12/2018
2.4.17 2,679 2/6/2018
2.4.16 2,927 2/2/2018
2.4.15 2,845 1/31/2018
2.4.14 2,818 1/31/2018
2.4.13 2,859 1/23/2018
2.4.12 2,795 1/16/2018
2.4.11 2,933 1/8/2018
2.4.10 3,038 1/5/2018
2.4.9 3,101 12/29/2017
2.4.8 4,688 12/6/2017
2.4.7 2,866 11/30/2017
2.4.6 2,860 11/27/2017
2.4.5 3,105 11/16/2017
2.4.4 2,911 11/13/2017
2.4.3 4,173 11/7/2017
2.4.2 2,847 11/1/2017
2.4.1 2,973 10/30/2017
2.4.0 11,793 9/30/2017
2.3.0 2,969 9/30/2017
2.2.1 2,926 9/24/2017
2.2.0-beta1 2,520 9/20/2017
2.1.15 3,709 8/31/2017
2.1.14 2,827 8/8/2017
2.1.13 2,942 8/2/2017
2.1.12 2,694 8/1/2017
2.1.11 2,802 7/27/2017
2.1.10 2,872 7/25/2017
2.1.9 2,844 7/11/2017
2.1.8 8,849 7/10/2017
2.1.7 2,865 7/7/2017
2.1.6 2,728 7/6/2017
2.1.5 2,802 7/3/2017
2.1.4 3,275 6/29/2017