-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a new filter expression for multiple search on strings #205
Merged
joukevandermaas
merged 12 commits into
joukevandermaas:master
from
PhyberApex:feature/csvfilter
Oct 25, 2018
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
69cb72f
Added a new filter expression
PhyberApex 0f66882
Switched from Expression to a more generic approach
PhyberApex e087116
Merge branch 'master' into feature/csvfilter
79f90f0
Added backwards campatibility
PhyberApex dad182f
Added generating of array via reflection
218b159
Uncommented test
PhyberApex 45cb954
Added suggested changes
e41cbbe
Merge branch 'feature/csvfilter' of https://github.com/PhyberApex/sau…
f743a13
Fixed expression chaining and multiple int test
cbbadca
Fixed code style
58d57d0
Fixed regex for CSV matching
66dbc4c
Added unit test for quotes in text
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using Saule.Http; | ||
using Expression = System.Linq.Expressions.Expression; | ||
|
||
namespace Saule.Queries | ||
{ | ||
|
@@ -22,7 +23,7 @@ public static Expression SelectPropertyValue(Type type, string property, List<st | |
return typeof(Lambda) | ||
.GetMethod(nameof(Convert), BindingFlags.Static | BindingFlags.NonPublic) | ||
.MakeGenericMethod(valueType, type) | ||
.Invoke(null, new[] { expression, parsedValues, propertyExpression, param }) | ||
.Invoke(null, new object[] { expression, parsedValues, propertyExpression, param }) | ||
as Expression; | ||
} | ||
|
||
|
@@ -50,15 +51,27 @@ internal static List<object> TryConvert(List<string> values, Type type) | |
return parsedList; | ||
} | ||
|
||
internal static object TryConvert(string value, Type type) | ||
{ | ||
var converter = TypeDescriptor.GetConverter(type); | ||
return converter.ConvertFromInvariantString(value); | ||
} | ||
|
||
// Return value is used through reflection invocation | ||
// ReSharper disable once UnusedMethodReturnValue.Local | ||
private static Expression<Func<TClass, bool>> Convert<TProperty, TClass>( | ||
Expression<Func<TProperty, TProperty, bool>> expression, | ||
TProperty constant, | ||
List<TProperty> constant, | ||
MemberExpression propertyExpression, | ||
ParameterExpression parameter) | ||
{ | ||
var curriedBody = new FilterLambdaVisitor<TProperty>(propertyExpression, constant).Visit(expression.Body); | ||
// initialize the expression with a always true one to make chaining possible | ||
Expression curriedBody = Expression.Lambda(Expression.Constant(true)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right my bad! |
||
foreach (TProperty c in constant) | ||
{ | ||
curriedBody = Expression.OrElse(curriedBody, new FilterLambdaVisitor<TProperty>(propertyExpression, c).Visit(expression.Body)); | ||
} | ||
|
||
return Expression.Lambda<Func<TClass, bool>>(curriedBody, parameter); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to call this for each filter, so instead of
(line 17)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had two
TryConvert
methods. One which took an array and one that only took a single one. I have those reduced to one now and added theSelect
function at the appropriate places.