mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-25 14:53:27 +01:00
nuget package and custom operators
This commit is contained in:
parent
e848b86a16
commit
8d1b01eb2c
@ -44,7 +44,8 @@ namespace Sieve.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
var tokens = _filter.Split(' ');
|
||||||
|
return tokens.Length > 1 ? tokens[1] : "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +98,12 @@ namespace Sieve.Services
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = ApplyCustomMethod(result, sortTerm.Name, _customSortMethods,
|
result = ApplyCustomMethod(result, sortTerm.Name, _customSortMethods,
|
||||||
isSorting: true,
|
new object[]
|
||||||
useThenBy: useThenBy,
|
{
|
||||||
desc: sortTerm.Descending);
|
result,
|
||||||
|
useThenBy,
|
||||||
|
sortTerm.Descending
|
||||||
|
});
|
||||||
}
|
}
|
||||||
useThenBy = true;
|
useThenBy = true;
|
||||||
}
|
}
|
||||||
@ -170,7 +173,12 @@ namespace Sieve.Services
|
|||||||
}
|
}
|
||||||
else
|
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,
|
private IQueryable<TEntity> ApplyCustomMethod(IQueryable<TEntity> result, string name, object parent, object[] parameters)
|
||||||
bool isSorting = false, bool useThenBy = false, bool desc = false)
|
|
||||||
{
|
{
|
||||||
var customMethod = parent?.GetType()
|
var customMethod = parent?.GetType()
|
||||||
.GetMethod(name);
|
.GetMethod(name);
|
||||||
|
|
||||||
if (customMethod != null)
|
if (customMethod != null)
|
||||||
{
|
{
|
||||||
var parameters = isSorting ? new object[] { result, useThenBy, desc } : new object[] { result };
|
|
||||||
result = customMethod.Invoke(parent, parameters)
|
result = customMethod.Invoke(parent, parameters)
|
||||||
as IQueryable<TEntity>;
|
as IQueryable<TEntity>;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.1-beta3" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
23
Sieve/Sieve.nuspec
Normal file
23
Sieve/Sieve.nuspec
Normal 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
BIN
Sieve/nuget.exe
Normal file
Binary file not shown.
@ -9,7 +9,7 @@ namespace SieveTests.Services
|
|||||||
{
|
{
|
||||||
public class SieveCustomFilterMethodsOfPosts : ISieveCustomFilterMethods<Post>
|
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 &&
|
var result = source.Where(p => p.LikeCount < 100 &&
|
||||||
p.CommentCount < 5);
|
p.CommentCount < 5);
|
||||||
|
Loading…
Reference in New Issue
Block a user