Skip to content

Latest commit

 

History

History
77 lines (73 loc) · 1.57 KB

File metadata and controls

77 lines (73 loc) · 1.57 KB

Guidelines.RestApi.Collections.Filtering

Implementation of the Filtering API of Microsoft Guidelines REST API using Superpower.

Supported comparison operators

  • Equal
var expression = "Id eq 1";
  • NotEqual
var expression = "Id ne 1";
  • GraterThan
var expression = "Id gt 1";
  • GraterThanOrEqual
var expression = "Id ge 1";
  • LessThan
var expression = "Id lt 1";
  • LessThanOrEqual
var expression = "Id le 1";
  • In
var expression = "Id in (1,2,3)";

Supported string functions

  • Length
var expression = "length(Title) gt 1";
  • StartsWith
var expression = "startswith(Title, 'Some')";
  • EndsWith
var expression = "endswith(Title, 'Title')";
  • Contains
var expression = "contains(Title, 'Title')";
  • IndexOf
var expression = "indexof(Title, 'Title') eq 0";

Supported logical operators

  • And
var expression = "Id eq 1 and Value ne 5.0";
  • Or
var expression = "Id eq 1 or Value ne 5.0";
  • Not
var expression = "not Id eq 1";

Usage

var expression = "(length(Title) gt 5 and contains(Title, 'tle')) or Id in (3,5)";
// Parse a filtering function
Expression<Func<Item, bool>> predicateExpression = FilterParser.Parse<Item>(expression);
// Compile a filtering function
Func<Item, bool> predicate = FilterCompiler.Compile<Item>(expression);