Z.Expressions.Eval 6.1.2

dotnet add package Z.Expressions.Eval --version 6.1.2
NuGet\Install-Package Z.Expressions.Eval -Version 6.1.2
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.2" />
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.2
#r "nuget: Z.Expressions.Eval, 6.1.2"
#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.2

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

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 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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 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 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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/EntityFramework-Effort
Entity Framework Effort is a powerful tool that enables a convenient way to create automated tests for Entity Framework based applications.
zzzprojects/Eval-Expression.NET
C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
DigitalPlatform/dp2
Integrated Library System / 图书馆集成系统
Version Downloads Last updated
6.1.2 85,186 3/11/2024
6.1.1 61,091 2/27/2024
6.1.0 125,882 2/13/2024
6.0.6 217,787 1/15/2024
6.0.5 142,385 12/18/2023
6.0.4 1,740 12/11/2023
6.0.3 81,380 12/5/2023
6.0.2 89,304 11/28/2023
6.0.1 1,063 11/28/2023
6.0.0 124,206 11/15/2023
5.0.12 2,281 11/7/2023
5.0.11 249,450 10/17/2023
5.0.10 176,235 9/26/2023
5.0.9 167,598 9/11/2023
5.0.8 184,295 8/15/2023
5.0.7 434,234 7/11/2023
5.0.6 250,663 6/12/2023
5.0.5 7,071 5/30/2023
5.0.4 346,774 5/16/2023
5.0.3 284,198 4/17/2023
5.0.2 287,096 3/20/2023
5.0.1 435,856 2/20/2023
5.0.0 689,172 1/17/2023
4.0.92 332,027 12/20/2022
4.0.91 302,866 12/5/2022
4.0.90 481,084 11/14/2022
4.0.89 829,673 10/10/2022
4.0.88 1,061,530 9/12/2022
4.0.87 646,060 8/16/2022
4.0.86 888,850 7/19/2022
4.0.85 711,326 6/14/2022
4.0.84 127,656 6/7/2022
4.0.83 22,709 5/26/2022
4.0.82 401,035 5/24/2022
4.0.81 191,366 5/17/2022
4.0.80 187,492 5/10/2022
4.0.79 686,207 4/12/2022
4.0.78 221,134 3/30/2022
4.0.77 626,013 3/15/2022
4.0.76 257,403 3/1/2022
4.0.75 136,157 2/22/2022
4.0.74 250,426 2/14/2022
4.0.73 116,032 2/8/2022
4.0.72 12,595 2/1/2022
4.0.71 517,854 1/18/2022
4.0.70 250,287 1/11/2022
4.0.69 1,092,805 12/30/2021
4.0.68 11,145 12/15/2021
4.0.67 249,374 12/14/2021
4.0.66 3,219 12/7/2021
4.0.65 2,730 11/30/2021
4.0.64 302,458 11/24/2021
4.0.63 298,341 11/17/2021
4.0.62 271,054 11/9/2021
4.0.61 2,859 11/4/2021
4.0.60 279,733 10/27/2021
4.0.59 139,372 10/20/2021
4.0.58 86,623 10/13/2021
4.0.57 2,563 10/12/2021
4.0.56 4,848 10/6/2021
4.0.55 5,457 9/29/2021
4.0.54 532,085 9/15/2021
4.0.53 105,742 9/8/2021
4.0.52 196,823 9/1/2021
4.0.51 83,061 8/25/2021
4.0.50 153,959 8/17/2021
4.0.49 165,007 8/4/2021
4.0.48 442,886 7/28/2021
4.0.47 178,926 7/20/2021
4.0.46 223,691 7/13/2021
4.0.45 496,260 6/16/2021
4.0.44 73,160 6/14/2021
4.0.43 449,933 5/12/2021
4.0.42 127,483 5/3/2021
4.0.41 207,427 4/26/2021
4.0.40 2,306 4/22/2021
4.0.39 85,825 4/19/2021
4.0.38 149,003 4/7/2021
4.0.37 244,918 3/24/2021
4.0.37-beta1 1,573 4/1/2021
4.0.36 139,430 3/16/2021
4.0.35 37,192 3/15/2021
4.0.34 190,333 3/10/2021
4.0.33 11,025 2/23/2021
4.0.32 563,754 2/16/2021
4.0.31 152,136 2/10/2021
4.0.30 156,387 2/2/2021
4.0.29 296,003 1/13/2021
4.0.28 539,850 12/14/2020
4.0.27 63,973 12/8/2020
4.0.26 101,835 12/1/2020
4.0.25 69,440 11/27/2020
4.0.24 196,455 11/11/2020
4.0.23 207,565 10/30/2020
4.0.22 680,156 10/11/2020
4.0.21 47,790 10/7/2020
4.0.20 3,033 10/5/2020
4.0.19 99,720 9/30/2020
4.0.18 4,224 9/29/2020
4.0.17 23,395 9/24/2020
4.0.16 298,404 9/14/2020
4.0.15 220,895 8/31/2020
4.0.14 6,996 8/25/2020
4.0.13 5,112 8/17/2020
4.0.12 222,087 8/11/2020
4.0.11 96,589 8/3/2020
4.0.10 16,337 7/28/2020
4.0.9 136,243 7/22/2020
4.0.8 3,121 7/19/2020
4.0.7 2,088 7/19/2020
4.0.6 247,198 7/14/2020
4.0.5 2,177 7/13/2020
4.0.4 88,581 7/12/2020
4.0.3 11,689 7/5/2020
4.0.2 7,538 6/30/2020
4.0.1 649,219 6/14/2020
4.0.0 78,427 6/1/2020
3.1.12 9,838 5/25/2020
3.1.11 647,861 5/14/2020
3.1.10 446,527 4/14/2020
3.1.9 46,803 4/3/2020
3.1.8 585,314 3/16/2020
3.1.7 5,776 3/10/2020
3.1.6 524,029 2/21/2020
3.1.5 294,743 2/18/2020
3.1.4 19,314 2/15/2020
3.1.3 52,444 2/7/2020
3.1.2 437,784 1/27/2020
3.1.1 3,954 1/23/2020
3.1.0 7,778 1/14/2020
3.0.14 5,626 1/13/2020
3.0.13 26,133 1/9/2020
3.0.12 5,033 1/3/2020
3.0.11 9,622 12/19/2019
3.0.10 3,550 12/17/2019
3.0.9 501,462 12/16/2019
3.0.8 5,638 12/11/2019
3.0.7 290,054 11/25/2019
3.0.6 23,585 11/18/2019
3.0.5 3,759 11/14/2019
3.0.4 7,684 11/12/2019
3.0.3 583,338 10/30/2019
3.0.2 2,136 10/30/2019
3.0.1 12,134 10/29/2019
3.0.0 2,533 10/29/2019
2.9.57 5,842 10/16/2019
2.9.56 2,572 10/10/2019
2.9.55 5,757 10/2/2019
2.9.54 15,708 9/22/2019
2.9.52 2,915 9/6/2019
2.9.51 2,176 9/5/2019
2.9.50 2,176 9/4/2019
2.9.49 2,621 8/29/2019
2.9.48 8,152 8/24/2019
2.9.47 2,238 8/24/2019
2.9.46 39,753 8/15/2019
2.9.45 155,333 7/28/2019
2.9.44 2,983 7/15/2019
2.9.43 3,429 7/9/2019
2.9.42 6,160 7/4/2019
2.9.41 2,372 7/3/2019
2.9.40 2,312 7/1/2019
2.9.39 15,205 6/29/2019
2.9.38 2,203 6/25/2019
2.9.37 2,698 6/12/2019
2.9.36 2,346 6/7/2019
2.9.35 2,202 6/4/2019
2.9.34 2,482 5/31/2019
2.9.33 4,136 5/31/2019
2.9.32 4,372 5/23/2019
2.9.31 26,956 5/20/2019
2.9.30 2,266 5/17/2019
2.9.29 2,308 5/9/2019
2.9.28 2,131 5/9/2019
2.9.27 4,286 5/5/2019
2.9.26 2,162 5/3/2019
2.9.25 6,952 4/30/2019
2.9.24 2,889 4/18/2019
2.9.22 2,342 4/16/2019
2.9.21 9,472 4/7/2019
2.9.20 31,970 3/30/2019
2.9.19 2,427 3/27/2019
2.9.18 2,272 3/26/2019
2.9.17 2,420 3/21/2019
2.9.16 2,176 3/20/2019
2.9.15 2,206 3/20/2019
2.9.14 2,346 3/16/2019
2.9.13 2,258 3/16/2019
2.9.12 87,184 2/27/2019
2.9.11 2,519 2/20/2019
2.9.10 2,262 2/18/2019
2.9.9 2,208 2/16/2019
2.9.8 2,898 2/13/2019
2.9.7 2,600 2/8/2019
2.9.6 5,977 1/30/2019
2.9.5 7,703 1/13/2019
2.9.4 5,503 12/30/2018
2.9.3 2,810 12/13/2018
2.9.2 2,396 12/13/2018
2.9.1 2,500 12/12/2018
2.9.0 2,329 12/12/2018
2.8.9 2,851 12/11/2018
2.8.8 69,612 11/29/2018
2.8.7 2,832 11/28/2018
2.8.6 2,345 11/27/2018
2.8.5 3,546 11/20/2018
2.8.4 2,456 11/18/2018
2.8.3 2,409 11/17/2018
2.8.2 2,421 11/17/2018
2.8.1 2,546 11/14/2018
2.8.0 2,335 11/14/2018
2.7.13 4,875 10/29/2018
2.7.12 9,274 10/28/2018
2.7.11 2,469 10/23/2018
2.7.10 3,301 10/17/2018
2.7.9 4,894 10/7/2018
2.7.8 5,322 9/29/2018
2.7.7 5,213 8/31/2018
2.7.6 5,857 8/30/2018
2.7.5 2,777 8/18/2018
2.7.4 5,171 8/16/2018
2.7.3 3,335 8/16/2018
2.7.2 4,668 7/31/2018
2.7.1 3,099 7/19/2018
2.7.0 3,112 7/5/2018
2.6.5 2,929 6/29/2018
2.6.4 3,618 5/31/2018
2.6.3 3,849 5/2/2018
2.6.2 2,915 4/30/2018
2.6.1 3,450 3/30/2018
2.6.0 2,848 3/26/2018
2.5.0 2,848 3/20/2018
2.4.21 2,677 3/20/2018
2.4.20 2,746 3/16/2018
2.4.19 3,248 2/27/2018
2.4.18 3,250 2/12/2018
2.4.17 2,587 2/6/2018
2.4.16 2,853 2/2/2018
2.4.15 2,780 1/31/2018
2.4.14 2,746 1/31/2018
2.4.13 2,777 1/23/2018
2.4.12 2,722 1/16/2018
2.4.11 2,862 1/8/2018
2.4.10 2,959 1/5/2018
2.4.9 3,025 12/29/2017
2.4.8 4,605 12/6/2017
2.4.7 2,778 11/30/2017
2.4.6 2,779 11/27/2017
2.4.5 3,030 11/16/2017
2.4.4 2,834 11/13/2017
2.4.3 3,959 11/7/2017
2.4.2 2,774 11/1/2017
2.4.1 2,901 10/30/2017
2.4.0 10,759 9/30/2017
2.3.0 2,893 9/30/2017
2.2.1 2,853 9/24/2017
2.2.0-beta1 2,433 9/20/2017
2.1.15 3,624 8/31/2017
2.1.14 2,751 8/8/2017
2.1.13 2,857 8/2/2017
2.1.12 2,621 8/1/2017
2.1.11 2,731 7/27/2017
2.1.10 2,779 7/25/2017
2.1.9 2,768 7/11/2017
2.1.8 8,688 7/10/2017
2.1.7 2,781 7/7/2017
2.1.6 2,627 7/6/2017
2.1.5 2,724 7/3/2017
2.1.4 3,171 6/29/2017