From d6265c3b8d83211b117c5d2b4fca1357b1fb63d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Leb=C3=A9e?= Date: Wed, 14 Mar 2018 18:26:30 -0500 Subject: [PATCH] refactoring with names that make more sense. --- PoweredSoft.DynamicLinq.Test/HelpersTests.cs | 6 +++--- .../Fluent/OrderBy/OrderByBuilder.cs | 2 +- .../Fluent/WhereBuilder/WhereBuilder.cs | 2 +- .../Helpers/QueryableHelpers.cs | 14 +++++++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/PoweredSoft.DynamicLinq.Test/HelpersTests.cs b/PoweredSoft.DynamicLinq.Test/HelpersTests.cs index 3c7a92a..5c124a1 100644 --- a/PoweredSoft.DynamicLinq.Test/HelpersTests.cs +++ b/PoweredSoft.DynamicLinq.Test/HelpersTests.cs @@ -80,9 +80,9 @@ namespace PoweredSoft.DynamicLinq.Test // the query. var query = authors.AsQueryable(); - var allExpression = QueryableHelpers.CreateFilterExpression("Posts.Title", ConditionOperators.Equal, "Match", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.All); - var anyExpression = QueryableHelpers.CreateFilterExpression("Posts.Title", ConditionOperators.Equal, "Match", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.Any); - var anyExpression2 = QueryableHelpers.CreateFilterExpression("Posts.Comments.Email", ConditionOperators.Equal, "John.doe@me.com", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.Any); + var allExpression = QueryableHelpers.CreateConditionExpression("Posts.Title", ConditionOperators.Equal, "Match", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.All); + var anyExpression = QueryableHelpers.CreateConditionExpression("Posts.Title", ConditionOperators.Equal, "Match", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.Any); + var anyExpression2 = QueryableHelpers.CreateConditionExpression("Posts.Comments.Email", ConditionOperators.Equal, "John.doe@me.com", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.Any); Assert.AreEqual(1, query.Count(allExpression)); Assert.AreEqual(2, query.Count(anyExpression)); Assert.AreEqual(1, query.Count(anyExpression2)); diff --git a/PoweredSoft.DynamicLinq/Fluent/OrderBy/OrderByBuilder.cs b/PoweredSoft.DynamicLinq/Fluent/OrderBy/OrderByBuilder.cs index de1ae3e..519c8d6 100644 --- a/PoweredSoft.DynamicLinq/Fluent/OrderBy/OrderByBuilder.cs +++ b/PoweredSoft.DynamicLinq/Fluent/OrderBy/OrderByBuilder.cs @@ -21,7 +21,7 @@ namespace PoweredSoft.DynamicLinq.Fluent Sorts.ForEach(sort => { - query = QueryableHelpers.CreateSortExpression(query, sort.Path, sort.sortDirection, sort.AppendSort); + query = QueryableHelpers.CreateOrderByExpression(query, sort.Path, sort.sortDirection, sort.AppendSort); }); return query; diff --git a/PoweredSoft.DynamicLinq/Fluent/WhereBuilder/WhereBuilder.cs b/PoweredSoft.DynamicLinq/Fluent/WhereBuilder/WhereBuilder.cs index 6a62811..e3b5c06 100644 --- a/PoweredSoft.DynamicLinq/Fluent/WhereBuilder/WhereBuilder.cs +++ b/PoweredSoft.DynamicLinq/Fluent/WhereBuilder/WhereBuilder.cs @@ -70,7 +70,7 @@ namespace PoweredSoft.DynamicLinq.Fluent protected virtual Expression> BuildFilterExpression(ParameterExpression parameter, WhereBuilderCondition filter) { - var ret = QueryableHelpers.CreateFilterExpression( + var ret = QueryableHelpers.CreateConditionExpression( filter.Path, filter.ConditionOperator, filter.Value, diff --git a/PoweredSoft.DynamicLinq/Helpers/QueryableHelpers.cs b/PoweredSoft.DynamicLinq/Helpers/QueryableHelpers.cs index b564851..1a0e26a 100644 --- a/PoweredSoft.DynamicLinq/Helpers/QueryableHelpers.cs +++ b/PoweredSoft.DynamicLinq/Helpers/QueryableHelpers.cs @@ -270,7 +270,7 @@ namespace PoweredSoft.DynamicLinq.Helpers throw new NotSupportedException($"{convertStrategy} supplied is not recognized"); } - public static IQueryable CreateSortExpression(IQueryable query, string sortPath, QuerySortDirection sortDirection, bool appendSort = true) + public static IQueryable CreateOrderByExpression(IQueryable query, string sortPath, QuerySortDirection sortDirection, bool appendSort = true) { var parameter = Expression.Parameter(typeof(T), "t"); var member = QueryableHelpers.ResolvePathForExpression(parameter, sortPath); @@ -306,7 +306,7 @@ namespace PoweredSoft.DynamicLinq.Helpers */ - internal static Expression InternalCreateFilterExpression(int recursionStep, Type type, ParameterExpression parameter, Expression current, List parts, + internal static Expression InternalCreateConditionExpression(int recursionStep, Type type, ParameterExpression parameter, Expression current, List parts, ConditionOperators condition, object value, QueryConvertStrategy convertStrategy, QueryCollectionHandling collectionHandling, bool nullChecking, StringComparison? stringComparison) { var partStr = parts.First(); @@ -346,7 +346,7 @@ namespace PoweredSoft.DynamicLinq.Helpers { var listGenericArgumentType = memberExpression.Type.GetGenericArguments().First(); var innerParameter = Expression.Parameter(listGenericArgumentType, $"t{++recursionStep}"); - var innerLambda = InternalCreateFilterExpression(recursionStep, listGenericArgumentType, innerParameter, innerParameter, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking, stringComparison); + var innerLambda = InternalCreateConditionExpression(recursionStep, listGenericArgumentType, innerParameter, innerParameter, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking, stringComparison); // the collection method. var collectionMethod = GetCollectionMethod(collectionHandling); @@ -365,12 +365,12 @@ namespace PoweredSoft.DynamicLinq.Helpers { if (nullCheckExpression != null) { - var pathExpr = InternalCreateFilterExpression(recursionStep, type, parameter, memberExpression, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking, stringComparison); + var pathExpr = InternalCreateConditionExpression(recursionStep, type, parameter, memberExpression, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking, stringComparison); var nullCheckResult = Expression.AndAlso(nullCheckExpression, pathExpr); return nullCheckResult; } - return InternalCreateFilterExpression(recursionStep, type, parameter, memberExpression, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking, stringComparison); + return InternalCreateConditionExpression(recursionStep, type, parameter, memberExpression, parts.Skip(1).ToList(), condition, value, convertStrategy, collectionHandling, nullChecking, stringComparison); } } @@ -422,7 +422,7 @@ namespace PoweredSoft.DynamicLinq.Helpers - public static Expression> CreateFilterExpression(string path, + public static Expression> CreateConditionExpression(string path, ConditionOperators condition, object value, QueryConvertStrategy convertStrategy, @@ -435,7 +435,7 @@ namespace PoweredSoft.DynamicLinq.Helpers parameter = Expression.Parameter(typeof(T), "t"); var parts = path.Split('.').ToList(); - var result = InternalCreateFilterExpression(1, typeof(T), parameter, parameter, parts, condition, value, convertStrategy, collectionHandling, nullChecking, stringComparision); + var result = InternalCreateConditionExpression(1, typeof(T), parameter, parameter, parts, condition, value, convertStrategy, collectionHandling, nullChecking, stringComparision); var ret = result as Expression>; return ret; }