Logo

SequelFilter is a C# library allowing objects to be filtered using a SQL like query language

Get the library via nuget:

Alternatively see the releases on GitHub:

Code usage 👩‍💻

Using SequelFilter from code is fairly simple.

To match a single object to a filter, you can use:

var matches = ObjectFilter.Matches(
    someObject,
    "Property > 5 AND OtherProperty == 'fred'");

If you want to apply the same filter to multiple objects, it is more efficient to first compile the expression and then apply it:

var filter = SequelFilterParser.Parse(
    "Property > 5 AND OtherProperty == 'fred'");
var matches = filter.Matches(someObject);

You can also filter IEnumerable instances like so:

var filteredResults = myEnumerable
    .Where("Property > 5 AND OtherProperty == 'fred'")
    .ToList();

Object resolution 🔍

When you compile a filter, you receive a delegate of type ExecutableExpression which is defined as:

delegate bool ExecutableExpression(IFieldReferenceResolver fieldReferenceResolver);

Effectively, IFieldReferenceResolver is used to resolve dotted field references. So if during executing the filter needs to get the value for a dotted reference, a call will be made to the Resolve member of IFieldReferenceResolver.

There are a couple of built in IFieldReferenceResolver types. For the examples below we will consider the dotted field reference first.second:

Exceptions 🤔

In the main part, SequelFilter can throw two exception types: