Skip to content

Commit

Permalink
Implement ExpressionBuildContext to DynamicFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
enisn committed Oct 17, 2023
1 parent 15f9e66 commit 1c1a1a9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/AutoFilterer.Dynamics/DynamicFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ public Expression BuildExpression(Type entityType, Expression body)

foreach (var key in this.Keys)
{
var filterPropertyExpression = Expression.Property(Expression.Constant(this), key);
var filterValue = new DynamicFilter(this[key]);
var getter = this.GetType().GetMethod("get_Item");
var filterPropertyExpression = Expression.Call(Expression.Constant(this), getter, Expression.Constant(key));
var filterValue = getter.Invoke(this, parameters: [key]);

Check failure on line 71 in src/AutoFilterer.Dynamics/DynamicFilter.cs

View workflow job for this annotation

GitHub Actions / build

The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.

Check failure on line 71 in src/AutoFilterer.Dynamics/DynamicFilter.cs

View workflow job for this annotation

GitHub Actions / build

The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
if (IsPrimitive(key))
{
var targetProperty = entityType.GetProperty(key);
var value = Convert.ChangeType((string)filterValue, targetProperty.PropertyType);
//var exp = OperatorComparisonAttribute.Equal.BuildExpression(body, targetProperty, filterProperty: null, value);

var exp = OperatorComparisonAttribute.Equal.BuildExpression(new ExpressionBuildContext(body, targetProperty, null, filterPropertyExpression, this, value));
var exp = OperatorComparisonAttribute.Equal.BuildExpression(
new ExpressionBuildContext(body, targetProperty, null, filterPropertyExpression, this, value));

var combined = finalExpression.Combine(exp, CombineWith);
finalExpression = body.Combine(combined, CombineWith);
Expand Down

0 comments on commit 1c1a1a9

Please sign in to comment.