mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-24 22:42:30 +01:00
Defer to interface
This commit is contained in:
parent
fe7234f571
commit
2a170df0c2
@ -6,9 +6,9 @@ namespace Sieve.Services
|
||||
{
|
||||
public interface ISieveProcessor
|
||||
{
|
||||
IQueryable<TEntity> ApplyAll<TEntity>(ISieveModel model, IQueryable<TEntity> source);
|
||||
IQueryable<TEntity> ApplySorting<TEntity>(ISieveModel model, IQueryable<TEntity> result);
|
||||
IQueryable<TEntity> ApplyFiltering<TEntity>(ISieveModel model, IQueryable<TEntity> result);
|
||||
IQueryable<TEntity> ApplyAll<TEntity>(ISieveModel model, IQueryable<TEntity> source, object[] dataForCustomMethods = null);
|
||||
IQueryable<TEntity> ApplySorting<TEntity>(ISieveModel model, IQueryable<TEntity> result, object[] dataForCustomMethods = null);
|
||||
IQueryable<TEntity> ApplyFiltering<TEntity>(ISieveModel model, IQueryable<TEntity> result, object[] dataForCustomMethods = null);
|
||||
IQueryable<TEntity> ApplyPagination<TEntity>(ISieveModel model, IQueryable<TEntity> result);
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ namespace Sieve.Services
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public IQueryable<TEntity> ApplyAll<TEntity>(ISieveModel model, IQueryable<TEntity> source)
|
||||
public IQueryable<TEntity> ApplyAll<TEntity>(ISieveModel model, IQueryable<TEntity> source, object[] dataForCustomMethods = null)
|
||||
{
|
||||
var result = source;
|
||||
|
||||
@ -57,10 +57,10 @@ namespace Sieve.Services
|
||||
return result;
|
||||
|
||||
// Sort
|
||||
result = ApplySorting(model, result);
|
||||
result = ApplySorting(model, result, dataForCustomMethods);
|
||||
|
||||
// Filter
|
||||
result = ApplyFiltering(model, result);
|
||||
result = ApplyFiltering(model, result, dataForCustomMethods);
|
||||
|
||||
// Paginate
|
||||
result = ApplyPagination(model, result);
|
||||
@ -68,7 +68,7 @@ namespace Sieve.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
public IQueryable<TEntity> ApplySorting<TEntity>(ISieveModel model, IQueryable<TEntity> result)
|
||||
public IQueryable<TEntity> ApplySorting<TEntity>(ISieveModel model, IQueryable<TEntity> result, object[] dataForCustomMethods = null)
|
||||
{
|
||||
if (model?.SortsParsed == null)
|
||||
return result;
|
||||
@ -90,7 +90,7 @@ namespace Sieve.Services
|
||||
result,
|
||||
useThenBy,
|
||||
sortTerm.Descending
|
||||
});
|
||||
}, dataForCustomMethods);
|
||||
}
|
||||
useThenBy = true;
|
||||
}
|
||||
@ -98,7 +98,7 @@ namespace Sieve.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
public IQueryable<TEntity> ApplyFiltering<TEntity>(ISieveModel model, IQueryable<TEntity> result)
|
||||
public IQueryable<TEntity> ApplyFiltering<TEntity>(ISieveModel model, IQueryable<TEntity> result, object[] dataForCustomMethods = null)
|
||||
{
|
||||
if (model?.FiltersParsed == null)
|
||||
return result;
|
||||
@ -168,7 +168,7 @@ namespace Sieve.Services
|
||||
result,
|
||||
filterTerm.Operator,
|
||||
filterTerm.Value
|
||||
});
|
||||
}, dataForCustomMethods);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,16 +202,31 @@ namespace Sieve.Services
|
||||
});
|
||||
}
|
||||
|
||||
private IQueryable<TEntity> ApplyCustomMethod<TEntity>(IQueryable<TEntity> result, string name, object parent, object[] parameters)
|
||||
private IQueryable<TEntity> ApplyCustomMethod<TEntity>(IQueryable<TEntity> result, string name, object parent, object[] parameters, object[] optionalParameters = null)
|
||||
{
|
||||
var customMethod = parent?.GetType()
|
||||
.GetMethod(name);
|
||||
|
||||
if (customMethod != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = customMethod.Invoke(parent, parameters)
|
||||
as IQueryable<TEntity>;
|
||||
}
|
||||
catch (TargetParameterCountException)
|
||||
{
|
||||
if (optionalParameters != null)
|
||||
{
|
||||
result = customMethod.Invoke(parent, parameters.Concat(optionalParameters).ToArray())
|
||||
as IQueryable<TEntity>;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user