Semisoft.ExpressionParser 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Semisoft.ExpressionParser --version 1.0.2
                    
NuGet\Install-Package Semisoft.ExpressionParser -Version 1.0.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="Semisoft.ExpressionParser" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Semisoft.ExpressionParser" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Semisoft.ExpressionParser" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Semisoft.ExpressionParser --version 1.0.2
                    
#r "nuget: Semisoft.ExpressionParser, 1.0.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.
#:package Semisoft.ExpressionParser@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Semisoft.ExpressionParser&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Semisoft.ExpressionParser&version=1.0.2
                    
Install as a Cake Tool

ExpressionParser

String expression parser for .NET 10 that translates dynamic filter strings into LINQ Expression Trees (Expression<Func<T, bool>>) for Entity Framework Core and IQueryable<T>.

Built on Dijkstra's Shunting-Yard algorithm and compile-time Regex Source Generators for minimal overhead and zero third-party runtime dependencies.


Features

  • Direct IQueryable<T> Integration: Fluent .Where("...") extension method.
  • SQL Translation Friendly: Generates native LINQ trees compatible with EF Core SQL translation.
  • Rich Operator Support:
    • Logical: and, or, not (with precedence and parentheses (...))
    • Comparison: eq, neq, lt, leq, gt, geq
    • String: Contains, StartsWith, EndsWith
  • Property-to-Property Comparisons: Compare two entity fields (e.g., EndDate gt StartDate).
  • Quote Escaping: Single quotes inside string literals via SQL-standard '' (e.g., 'O''Reilly').
  • Null Safety: Built-in support for eq null and neq null on nullable types.
  • Comprehensive Type Support:
    • Integers: byte, sbyte, short, ushort, int, uint, long, ulong
    • Floating & Decimal: float, double, decimal
    • Date & Time: DateTime (UTC), DateOnly, TimeOnly
    • Text & Logical: string, char, bool
    • All corresponding Nullable<T> variants.

Building and Testing

Prerequisites

Build

dotnet build

Run Tests

Tests run against a real PostgreSQL 16 instance via Testcontainers:

dotnet test

Run Benchmarks

dotnet run -c Release --project ExpressionParser.Benchmark

Quick Start

Import the namespace and use .Where(string) on any IQueryable<T>:

using ExpressionParser;

// Filter users with a dynamic query
var activeAdults = await dbContext.Users
    .Where("Age geq 18 and Status eq 'Active'")
    .ToListAsync();

Examples

1. Logical Precedence and Parentheses

var users = await dbContext.Users
    .Where("(Age geq 18 and Age leq 60) or Status eq 'Staff'")
    .ToListAsync();

2. Direct Boolean Flags and not

// Evaluates boolean properties directly without redundant 'eq true'
var activeUsers = await dbContext.Users
    .Where("IsActive and not IsBanned")
    .ToListAsync();

3. String Operations and Escaped Quotes

// Double single-quotes '' unescape to a single quote '
var developers = await dbContext.Users
    .Where("LastName eq 'O''Reilly' and Email EndsWith '@company.com' and Bio Contains 'C#'")
    .ToListAsync();

4. Property-to-Property Comparison

// Compare columns against each other
var overdueTasks = await dbContext.Tasks
    .Where("CompletedDate gt DueDate")
    .ToListAsync();

5. Date and Time Filtering (UTC)

var recentRegistrations = await dbContext.Users
    .Where("CreatedAt geq '2025-01-01T00:00:00' and BirthDate leq '2005-01-01'")
    .ToListAsync();

6. Null Checks

var completedProfiles = await dbContext.Users
    .Where("PhoneNumber neq null and DeletedAt eq null")
    .ToListAsync();

Syntax Reference

Operator Description Example
eq Equal Status eq 'Active'
neq Not equal Role neq 'Guest'
lt Less than Price lt 100
leq Less than or equal Age leq 18
gt Greater than Score gt 50
geq Greater than or equal Salary geq 50000
and Logical AND A eq 1 and B eq 2
or Logical OR Role eq 'Admin' or Role eq 'User'
not Logical NOT not IsDeleted / not (A eq B)
Contains Substring match Name Contains 'smith'
StartsWith Prefix match Code StartsWith 'INV-'
EndsWith Suffix match Email EndsWith '.org'

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

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.3 96 11/9/2026
1.0.2 94 11/9/2026
1.0.1 91 11/9/2026