This commit is contained in:
Biarity
2019-11-17 08:58:12 +10:00
9 changed files with 113 additions and 13 deletions

View File

@@ -13,6 +13,7 @@ namespace Sieve.Models
private static readonly string[] Operators = new string[] {
"!@=*",
"!_=*",
"!=*",
"!@=",
"!_=",
"==*",

View File

@@ -186,6 +186,8 @@ namespace Sieve.Services
{
propertyValue = Expression.PropertyOrField(propertyValue, part);
}
if (filterTerm.Values == null) continue;
foreach (var filterTermValue in filterTerm.Values)
{
@@ -335,10 +337,9 @@ namespace Sieve.Services
var pageSize = model?.PageSize ?? _options.Value.DefaultPageSize;
var maxPageSize = _options.Value.MaxPageSize > 0 ? _options.Value.MaxPageSize : pageSize;
result = result.Skip((page - 1) * pageSize);
if (pageSize > 0)
{
result = result.Skip((page - 1) * pageSize);
result = result.Take(Math.Min(pageSize, maxPageSize));
}
@@ -387,6 +388,28 @@ namespace Sieve.Services
_options.Value.CaseSensitive ? BindingFlags.Default : BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance,
typeof(IQueryable<TEntity>));
if (customMethod == null)
{
// Find generic methods `public IQueryable<T> Filter<T>(IQueryable<T> source, ...)`
var genericCustomMethod = parent?.GetType()
.GetMethodExt(name,
_options.Value.CaseSensitive ? BindingFlags.Default : BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance,
typeof(IQueryable<>));
if (genericCustomMethod != null &&
genericCustomMethod.ReturnType.IsGenericType &&
genericCustomMethod.ReturnType.GetGenericTypeDefinition() == typeof(IQueryable<>))
{
var genericBaseType = genericCustomMethod.ReturnType.GenericTypeArguments[0];
var constraints = genericBaseType.GetGenericParameterConstraints();
if (constraints == null || constraints.Length == 0 || constraints.All((t) => t.IsAssignableFrom(typeof(TEntity))))
{
customMethod = genericCustomMethod.MakeGenericMethod(typeof(TEntity));
}
}
}
if (customMethod != null)
{
try