Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sieve.Sample/Sieve.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Sieve/Services/SieveProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ private IQueryable<TEntity> ApplyCustomMethod<TEntity>(IQueryable<TEntity> resul
var customMethod = parent?.GetType()
.GetMethodExt(name,
Options.Value.CaseSensitive
? BindingFlags.Default
: BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance,
? BindingFlags.Default | BindingFlags.Static
: BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static,
typeof(IQueryable<TEntity>));


Expand Down
26 changes: 25 additions & 1 deletion SieveUnitTests/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,30 @@ public void CanFilterWithEscapedOperators(string filter)
Assert.NotNull(entry);
Assert.Equal(1, resultCount);
}


[Theory]
[InlineData(@"HasInTitleStatic@=Tale", 1)]
[InlineData(@"HasInTitleStatic@=Tail", 0)]
public void CanFilterWithStaticFilters(string filter, int expectedMatches)
{
var posts = new List<Post>
{
new()
{
Id = 1,
Title = "A Tale of Two Cities",
}
}.AsQueryable();

var model = new SieveModel
{
Filters = filter
};

var result = _processor.Apply(model, posts);
var resultCount = result.Count();
Assert.Equal(expectedMatches, resultCount);
}

}
}
7 changes: 7 additions & 0 deletions SieveUnitTests/Services/SieveCustomFilterMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public IQueryable<IPost> HasInTitle(IQueryable<IPost> source, string op, string[
return result;
}

public static IQueryable<IPost> HasInTitleStatic(IQueryable<Post> source, string op, string[] values)
{
var result = source.Where(p => p.Title.Contains(values[0]));

return result;
}

public IQueryable<IComment> IsNew(IQueryable<IComment> source, string op, string[] values)
{
var result = source.Where(c => c.DateCreated > DateTimeOffset.UtcNow.AddDays(-2));
Expand Down
2 changes: 1 addition & 1 deletion SieveUnitTests/SieveUnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
Expand Down