Skip to content

Commit

Permalink
#126 fixed ignore case issue for contains search
Browse files Browse the repository at this point in the history
  • Loading branch information
ekondur committed Jun 6, 2023
1 parent 84981fc commit e7a8783
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions DatatableJS.Data/Builders/ExpressionBuilder.cs
Expand Up @@ -6,14 +6,13 @@

namespace DatatableJS.Data
{
public static class ExpressionBuilder
internal static class ExpressionBuilder
{
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 startsWithMethod = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) });
private static readonly MethodInfo endsWithMethod = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) });

public static Expression<Func<T, bool>> GetExpression<T>(FilterDef filter)
private static readonly MethodInfo indexOfMethod = typeof(string).GetMethod("IndexOf", new[] { typeof(string), typeof(StringComparison) });
internal static Expression<Func<T, bool>> GetExpression<T>(FilterDef filter)
{
if (filter == null)
{
Expand All @@ -39,7 +38,7 @@ private static Expression GetExpression(ParameterExpression param, FilterDef fil
}
var propertyValue = converter.ConvertFromInvariantString(filter.Value);
ConstantExpression constant = Expression.Constant(propertyValue, member.Type);
ConstantExpression ignoreCase = Expression.Constant(StringComparison.OrdinalIgnoreCase);
ConstantExpression ignoreCase = Expression.Constant(StringComparison.OrdinalIgnoreCase, typeof(StringComparison));

switch (filter.Operand)
{
Expand Down Expand Up @@ -68,7 +67,7 @@ private static Expression GetExpression(ParameterExpression param, FilterDef fil
}
else
{
return Expression.Call(member, containsMethodIgnoreCase, constant, ignoreCase);
return Expression.NotEqual(Expression.Call(member, indexOfMethod, constant, ignoreCase), Expression.Constant(-1, typeof(int)));
}

case Operand.StartsWith:
Expand All @@ -81,7 +80,7 @@ private static Expression GetExpression(ParameterExpression param, FilterDef fil
}
}

public static Expression<Func<T, bool>> GetExpression<T>(IList<FilterDef> filters)
internal static Expression<Func<T, bool>> GetExpression<T>(IList<FilterDef> filters)
{
if (filters.Count == 0)
{
Expand Down

0 comments on commit e7a8783

Please sign in to comment.