Convert parsing from getters to methods

This commit is contained in:
Biarity 2018-07-06 11:12:45 +10:00
parent c816cf2f2a
commit f9c7fb4cb0
4 changed files with 57 additions and 63 deletions

View File

@ -20,8 +20,8 @@ namespace Sieve.Models
int? PageSize { get; set; } int? PageSize { get; set; }
List<TFilterTerm> FiltersParsed { get; } List<TFilterTerm> GetFiltersParsed();
List<TSortTerm> SortsParsed { get; } List<TSortTerm> GetSortsParsed();
} }
} }

View File

@ -25,9 +25,7 @@ namespace Sieve.Models
[DataMember, Range(1, int.MaxValue)] [DataMember, Range(1, int.MaxValue)]
public int? PageSize { get; set; } public int? PageSize { get; set; }
public List<TFilterTerm> FiltersParsed public List<TFilterTerm> GetFiltersParsed()
{
get
{ {
if (Filters != null) if (Filters != null)
{ {
@ -65,11 +63,8 @@ namespace Sieve.Models
return null; return null;
} }
} }
}
public List<TSortTerm> SortsParsed public List<TSortTerm> GetSortsParsed()
{
get
{ {
if (Sorts != null) if (Sorts != null)
{ {
@ -97,4 +92,3 @@ namespace Sieve.Models
} }
} }
} }
}

View File

@ -164,14 +164,14 @@ namespace Sieve.Services
IQueryable<TEntity> result, IQueryable<TEntity> result,
object[] dataForCustomMethods = null) object[] dataForCustomMethods = null)
{ {
if (model?.FiltersParsed == null) if (model?.GetFiltersParsed() == null)
{ {
return result; return result;
} }
Expression outerExpression = null; Expression outerExpression = null;
var parameterExpression = Expression.Parameter(typeof(TEntity), "e"); var parameterExpression = Expression.Parameter(typeof(TEntity), "e");
foreach (var filterTerm in model.FiltersParsed) foreach (var filterTerm in model.GetFiltersParsed())
{ {
Expression innerExpression = null; Expression innerExpression = null;
foreach (var filterTermName in filterTerm.Names) foreach (var filterTermName in filterTerm.Names)
@ -281,13 +281,13 @@ namespace Sieve.Services
IQueryable<TEntity> result, IQueryable<TEntity> result,
object[] dataForCustomMethods = null) object[] dataForCustomMethods = null)
{ {
if (model?.SortsParsed == null) if (model?.GetSortsParsed() == null)
{ {
return result; return result;
} }
var useThenBy = false; var useThenBy = false;
foreach (var sortTerm in model.SortsParsed) foreach (var sortTerm in model.GetSortsParsed())
{ {
var property = GetSieveProperty<TEntity>(true, false, sortTerm.Name); var property = GetSieveProperty<TEntity>(true, false, sortTerm.Name);

View File

@ -148,9 +148,9 @@ namespace SieveUnitTests
Filters = "LikeCount==50", Filters = "LikeCount==50",
}; };
Console.WriteLine(model.FiltersParsed[0].Value); Console.WriteLine(model.GetFiltersParsed()[0].Value);
Console.WriteLine(model.FiltersParsed[0].Operator); Console.WriteLine(model.GetFiltersParsed()[0].Operator);
Console.WriteLine(model.FiltersParsed[0].OperatorParsed); Console.WriteLine(model.GetFiltersParsed()[0].OperatorParsed);
var result = _processor.Apply(model, _posts); var result = _processor.Apply(model, _posts);