From 9974365ee6e59fa9ea4efc284d3646a8bec1f04c Mon Sep 17 00:00:00 2001 From: dnyaneshwar-surywanshi <49733309+dnyaneshwar-surywanshi@users.noreply.github.com> Date: Mon, 25 Oct 2021 13:15:35 +0530 Subject: [PATCH 1/3] I want To make the "Contains" method become case-insensitive so I have modified CreateFilter and added new initialization for _containsMethodIgnoreCase. --- DynamicExpressions/DynamicExpressions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DynamicExpressions/DynamicExpressions.cs b/DynamicExpressions/DynamicExpressions.cs index b8ddf25..65ca2fb 100644 --- a/DynamicExpressions/DynamicExpressions.cs +++ b/DynamicExpressions/DynamicExpressions.cs @@ -12,6 +12,8 @@ public static class DynamicExpressions private static readonly MethodInfo _containsMethod = typeof(string).GetMethod("Contains" , new Type[] { typeof(string) }); + private static readonly MethodInfo _containsMethodIgnoreCase = typeof(string).GetMethod("Contains" + , new Type[] { typeof(string), typeof(StringComparison) }); private static readonly MethodInfo _endsWithMethod = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) }); @@ -51,6 +53,7 @@ private static Expression CreateFilter(MemberExpression prop, FilterOperator op, FilterOperator.GreaterThan => Expression.GreaterThan(prop, constant), FilterOperator.LessThan => Expression.LessThan(prop, constant), FilterOperator.Contains => Expression.Call(prop, _containsMethod, PrepareConstant(constant)), + FilterOperator.ContainsIgnoreCase => Expression.Call(prop, _containsMethodIgnoreCase, PrepareConstant(constant), Expression.Constant(StringComparison.OrdinalIgnoreCase)), FilterOperator.StartsWith => Expression.Call(prop, _startsWithMethod, PrepareConstant(constant)), FilterOperator.EndsWith => Expression.Call(prop, _endsWithMethod, PrepareConstant(constant)), FilterOperator.DoesntEqual => Expression.NotEqual(prop, constant), From f305d151fb4426e3adbb7f5f5b30962bb3da27d9 Mon Sep 17 00:00:00 2001 From: dnyaneshwar-surywanshi <49733309+dnyaneshwar-surywanshi@users.noreply.github.com> Date: Fri, 29 Oct 2021 11:22:22 +0530 Subject: [PATCH 2/3] Included ContainsIgnoreCase operator . --- DynamicExpressions/FilterOperator.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DynamicExpressions/FilterOperator.cs b/DynamicExpressions/FilterOperator.cs index cef71d8..2b5eb10 100644 --- a/DynamicExpressions/FilterOperator.cs +++ b/DynamicExpressions/FilterOperator.cs @@ -10,6 +10,7 @@ public enum FilterOperator LessThanOrEqual, Contains, StartsWith, - EndsWith + EndsWith, + ContainsIgnoreCase } } From 38838be2b79bbaf3b9497f014529ba2fe4fe202b Mon Sep 17 00:00:00 2001 From: zHaytam Date: Sun, 14 Nov 2021 23:01:34 +0100 Subject: [PATCH 3/3] Update PredicateTests.cs --- DynamicExpressions.UnitTests/PredicateTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/DynamicExpressions.UnitTests/PredicateTests.cs b/DynamicExpressions.UnitTests/PredicateTests.cs index 4b60348..3da11ce 100644 --- a/DynamicExpressions.UnitTests/PredicateTests.cs +++ b/DynamicExpressions.UnitTests/PredicateTests.cs @@ -43,6 +43,7 @@ public void GetPredicate_ShouldHandleEqualsGenericOperators(int id, T title, [InlineData(3, "Title 3", FilterOperator.NotContains, "5")] [InlineData(4, "Title 4", FilterOperator.StartsWith, "Title")] [InlineData(5, "Title 5", FilterOperator.EndsWith, "5")] + [InlineData(5, "Title 6", FilterOperator.ContainsIgnoreCase, "title")] public void GetPredicate_ShouldHandleNestedStringOperators(int id, string title, FilterOperator op, object value) { var entry = new Entry(id, new SubEntry(title));