nuget package and custom operators

This commit is contained in:
Biarity 2018-01-28 09:20:51 +10:00
parent e848b86a16
commit 8d1b01eb2c
6 changed files with 40 additions and 11 deletions

View File

@ -44,7 +44,8 @@ namespace Sieve.Models
}
}
return "";
var tokens = _filter.Split(' ');
return tokens.Length > 1 ? tokens[1] : "";
}
}

View File

@ -97,10 +97,13 @@ namespace Sieve.Services
}
else
{
result = ApplyCustomMethod(result, sortTerm.Name, _customSortMethods,
isSorting: true,
useThenBy: useThenBy,
desc: sortTerm.Descending);
result = ApplyCustomMethod(result, sortTerm.Name, _customSortMethods,
new object[]
{
result,
useThenBy,
sortTerm.Descending
});
}
useThenBy = true;
}
@ -170,7 +173,12 @@ namespace Sieve.Services
}
else
{
result = ApplyCustomMethod(result, filterTerm.Name, _customFilterMethods);
result = ApplyCustomMethod(result, filterTerm.Name, _customFilterMethods,
new object[] {
result,
filterTerm.Operator,
filterTerm.Value
});
}
}
@ -204,15 +212,13 @@ namespace Sieve.Services
});
}
private IQueryable<TEntity> ApplyCustomMethod(IQueryable<TEntity> result, string name, object parent,
bool isSorting = false, bool useThenBy = false, bool desc = false)
private IQueryable<TEntity> ApplyCustomMethod(IQueryable<TEntity> result, string name, object parent, object[] parameters)
{
var customMethod = parent?.GetType()
.GetMethod(name);
if (customMethod != null)
{
var parameters = isSorting ? new object[] { result, useThenBy, desc } : new object[] { result };
result = customMethod.Invoke(parent, parameters)
as IQueryable<TEntity>;
}

View File

@ -6,7 +6,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.1-beta3" />
</ItemGroup>
</Project>

23
Sieve/Sieve.nuspec Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Sieve</id>
<version>1.2</version>
<title>Sieve</title>
<authors>Biarity</authors>
<owners>Biarity</owners>
<licenseUrl>https://github.com/Biarity/Sieve/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/Biarity/Sieve</projectUrl>
<iconUrl>https://emojipedia-us.s3.amazonaws.com/thumbs/240/emoji-one/104/control-knobs_1f39b.png</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Sieve is a simple, clean, and extensible framework for .NET Core that adds sorting, filtering, and pagination functionality out of the box. Most common use case would be for serving ASP.NET Core GET queries.</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2018</copyright>
<tags>aspnetcore filter sort page paginate sieve search</tags>
<dependencies>
<group targetFramework=".NETCoreApp2.0">
<dependency id="Microsoft.Extensions.Options" version="2.0.0" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
</package>

BIN
Sieve/nuget.exe Normal file

Binary file not shown.

View File

@ -9,7 +9,7 @@ namespace SieveTests.Services
{
public class SieveCustomFilterMethodsOfPosts : ISieveCustomFilterMethods<Post>
{
public IQueryable<Post> IsNew(IQueryable<Post> source)
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value)
{
var result = source.Where(p => p.LikeCount < 100 &&
p.CommentCount < 5);