Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/BootstrapBlazor/Extensions/LambdaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ private static Expression GetExpression(this FilterKeyValueAction filter, Expres

private static BinaryExpression Contains(this Expression left, Expression right)
{
var method = typeof(string).GetMethod("Contains", [typeof(string)])!;
return Expression.AndAlso(Expression.NotEqual(left, Expression.Constant(null)), Expression.Call(left, method, right));
var method = typeof(string).GetMethod("Contains", [typeof(string), typeof(StringComparison)])!;
var comparison = Expression.Constant(StringComparison.OrdinalIgnoreCase);
return Expression.AndAlso(Expression.NotEqual(left, Expression.Constant(null)), Expression.Call(left, method, right, comparison));
Comment on lines +234 to +235
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider making StringComparison configurable instead of hardcoding OrdinalIgnoreCase.

Allowing the caller to specify the StringComparison would improve flexibility and accommodate different comparison needs.

Suggested implementation:

    private static BinaryExpression Contains(this Expression left, Expression right, StringComparison comparisonType)
    {
        var method = typeof(string).GetMethod("Contains", [typeof(string), typeof(StringComparison)])!;
        var comparison = Expression.Constant(comparisonType);
        return Expression.AndAlso(Expression.NotEqual(left, Expression.Constant(null)), Expression.Call(left, method, right, comparison));
    }

You will need to update all usages of the Contains extension method to pass the desired StringComparison value as an argument.

}

#region Count
Expand Down
4 changes: 4 additions & 0 deletions test/UnitTest/Extensions/LambadaExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ public void GetExpression_Contains()
var filter = new FilterKeyValueAction() { FieldKey = "Name", FieldValue = "test", FilterAction = FilterAction.Contains };
var invoker = filter.GetFilterLambda<Foo>().Compile();
Assert.True(invoker.Invoke(new Foo() { Name = "1test1" }));
Assert.True(invoker.Invoke(new Foo() { Name = "1Test1" }));
Assert.True(invoker.Invoke(new Foo() { Name = "1Test123" }));
Assert.True(invoker.Invoke(new Foo() { Name = "Test" }));
Assert.True(invoker.Invoke(new Foo() { Name = "Test2" }));
}

[Fact]
Expand Down
Loading