dotnet-dynamic-filter-expression
1.0.0
dotnet add package dotnet-dynamic-filter-expression --version 1.0.0
NuGet\Install-Package dotnet-dynamic-filter-expression -Version 1.0.0
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="dotnet-dynamic-filter-expression" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="dotnet-dynamic-filter-expression" Version="1.0.0" />
<PackageReference Include="dotnet-dynamic-filter-expression" />
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 dotnet-dynamic-filter-expression --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: dotnet-dynamic-filter-expression, 1.0.0"
#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 dotnet-dynamic-filter-expression@1.0.0
#: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=dotnet-dynamic-filter-expression&version=1.0.0
#tool nuget:?package=dotnet-dynamic-filter-expression&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Dotnet Dynamic Filter Expression
This libary will help translate string into a C# Expression Tree
Example: ((Name eq `Phuc Nguyen`) & (Age gt `25`))
⇒ x => x.Name == "Phuc Nguyen" && x.Age > 25
Example Code:
using FilterExpression;
using FilterExpression.Extension;
var list = new List<Customer>
{
new Customer{ Name = "Name 1", Age = 25, Id = 1, BirthDay = new DateTime(1997, 9, 15) },
new Customer{ Name = "Name 2", Age = 35, Id = 2, BirthDay = new DateTime(1990, 1, 1) },
new Customer{ Name = "Name 3", Age = 15, Id = 3, BirthDay = new DateTime(2000, 5, 1) },
};
var filterService = new FilterService();
var filter = filterService.Filter<Customer>("(BirthDay le `1997-9-15`)");
var filteredList = list.Where(filter.Compile()).ToArray();
// Another way
var filteredList = list.Filter("(BirthDay le `1997-9-15`)");
// Supported for IQueryable
var filteredList = list.AsQueryable.Filter("(BirthDay le `1997-9-15`)").ToList();
Supported Operator
- Equal:
(Name eq `Phuc Nguyen`)
- Not Equal:
(Name ne `Phuc Nguyen`)
- Greater than:
(Age gt `25`)
- Greater than and equal
(Age ge `25`)
- Less than:
(Age lt `25`)
- Less than and equal
(Age le `25`)
- Contains:
(Name contains `P`)
- StartsWith:
(Name StartsWith `P`)
- In:
(Age in `[25, 26]`)
- And:
( (Age eq `25`) & (Name eq `Phuc`))
- Or:
( (Age eq `25`) | (Name eq `Phuc`))
- Not:
!(Name eq `Phuc Nguyen`)
Custom Filter
You can create a custom filter syntax by implement IFilterDirective interface
Example
using System.Linq.Expressions;
namespace FilterExpression.Directive
{
internal class EqualDirective : IFilterDirective
{
public string FilterSyntax
{
get
{
return "eq"; // Syntax will be used in FilterExpression string
}
}
// Build expression tree here
public Expression GenerateExpression(ref MemberExpression property, ConstantExpression value)
{
return Expression.Equal(property, value);
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. 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. net10.0 was computed. 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.
-
net8.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.0 | 288 | 6/10/2025 |