Ramstack.ExpressionParser
1.0.0-beta.1
See the version list below for details.
dotnet add package Ramstack.ExpressionParser --version 1.0.0-beta.1
NuGet\Install-Package Ramstack.ExpressionParser -Version 1.0.0-beta.1
<PackageReference Include="Ramstack.ExpressionParser" Version="1.0.0-beta.1" />
paket add Ramstack.ExpressionParser --version 1.0.0-beta.1
#r "nuget: Ramstack.ExpressionParser, 1.0.0-beta.1"
// Install Ramstack.ExpressionParser as a Cake Addin #addin nuget:?package=Ramstack.ExpressionParser&version=1.0.0-beta.1&prerelease // Install Ramstack.ExpressionParser as a Cake Tool #tool nuget:?package=Ramstack.ExpressionParser&version=1.0.0-beta.1&prerelease
Ramstack.ExpressionParser
Ramstack.ExpressionParser is a flexible expression parser library for .NET, allowing dynamic evaluation and binding of expressions with context-aware support.
Getting Started
To install the Ramstack.ExpressionParser
NuGet package to your project, run the following command:
dotnet add package Ramstack.ExpressionParser
Usage
var result = ExpressionParser.Parse("math.min(2 + 3, 2 * 3)");
if (result.Success)
{
var lambda = Expression.Lambda<Func<int>>(result.Value);
var fn = lambda.Compile();
Console.WriteLine(fn());
}
Using ContextAwareBinder
ContextAwareBinder
allows binding expressions to a specific context,
making it possible to reference its properties, fields, and methods directly within expressions.
- The provided context acts as an implicit this, meaning you can access its members without prefixes.
- Case-insensitive binding: identifiers in expressions are resolved in case-insensitive manner (e.g., level, Level, and LEVEL are treated the same).
var parameter = Expression.Parameter(typeof(LogEvent), "logEvent");
var binder = new ContextAwareBinder(parameter);
var result = ExpressionParser.Parse("level == LogLevel.Error && string.IsNullOrEmpty(source)", binder);
var predicate = Expression
.Lambda<Predicate<LogEvent>>(result.Value, parameter)
.Compile();
Here, IsEnabled
evaluates the parsed expression against a LogEvent
instance:
public bool IsEnabled(LogEvent logEvent)
{
return _predicate(logEvent);
}
This makes it easy to create dynamic, human-readable expressions for filtering or evaluating objects at runtime.
Supported Versions
Version | |
---|---|
.NET | 6, 7, 8, 9 |
Contributions
Bug reports and contributions are welcome.
License
This package is released under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net6.0
- Ramstack.Parsing (>= 1.0.0-beta.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-beta.2 | 60 | 2/21/2025 |
1.0.0-beta.1 | 60 | 2/20/2025 |