Skip to content

Commit

Permalink
Release latest code. (#7)
Browse files Browse the repository at this point in the history
* test: Added more tests for logic operations
* docs: updated readme
  • Loading branch information
prakashrx committed Sep 26, 2022
1 parent 2abb38a commit 8b5f1df
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ dotnet add package DynamicFilter.Sql

## Usage/Examples

The `Compile` function takes a generic parameter that is used to determine the entity fields. This could be a user defined class or it could be a `Dictionary<string, object>` type.

#### User defined class

With a user defined class, the field names within the filter expression have to match the property names defined within the class. This is resolved at compile time.

```csharp
var myfilter = FilterExpression.Compile<User>("(Age > 10) and (Name like 'Alice%' or Name like 'Bob%')");

Expand All @@ -25,6 +31,36 @@ var names = users.Where(myfilter).Select(u => u.Name);

```

#### Dictionary

```csharp
var dict = new Dictionary<string, object> {
{"Name" , "Alice"},
{"Age" , 12},
};

var filter = FilterExpression.Compile<Dictionary<string, object>>("(Age > 10) and (Name like 'Alice%' or Name like 'Bob%')");

var match = filter(dict); //returns true
```

## Features

- Compile to .NET IL code.
- Support Sql Comparison operations
- =, <, >, <=, >=
- like, not like
- in, not in
- is null, is not null
- Dictionary and User objects

## Use cases

- Dynamically generate code to filter objects in memory
- Filter a stream of data with a multiple criteria
- User Preferences/Filters that could be potentially saved/loaded from a File/Database.

## Authors

- [@prakashrx](https://github.com/prakashrx)

0 comments on commit 8b5f1df

Please sign in to comment.