-
-
Notifications
You must be signed in to change notification settings - Fork 373
feat(Filter): add StringComparison parameter #7449
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
Changes from all commits
4cfd99f
a535df0
c9663fc
8cb296e
b0b5dc2
e874cf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,27 +34,27 @@ private class ComboExpressionVisitor(ParameterExpression parameter) : Expression | |||||||
| /// </summary> | ||||||||
| /// <typeparam name="TItem"></typeparam> | ||||||||
| /// <param name="filter"></param> | ||||||||
| /// <returns></returns> | ||||||||
| public static Func<TItem, bool> GetFilterFunc<TItem>(this FilterKeyValueAction filter) => filter.GetFilterLambda<TItem>().Compile(); | ||||||||
| /// <param name="comparison"><see cref="StringComparison"/> 实例,此方法不支持 EFCore Where 查询</param> | ||||||||
| public static Func<TItem, bool> GetFilterFunc<TItem>(this FilterKeyValueAction filter, StringComparison? comparison = null) => filter.GetFilterLambda<TItem>(comparison).Compile(); | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// 指定 FilterKeyValueAction 获取 Lambda 表达式 | ||||||||
| /// </summary> | ||||||||
| /// <typeparam name="TItem"></typeparam> | ||||||||
| /// <param name="filter"></param> | ||||||||
| /// <returns></returns> | ||||||||
| public static Expression<Func<TItem, bool>> GetFilterLambda<TItem>(this FilterKeyValueAction filter) | ||||||||
| /// <param name="comparison"><see cref="StringComparison"/> 实例,此方法不支持 EFCore Where 查询</param> | ||||||||
|
||||||||
| /// <param name="comparison"><see cref="StringComparison"/> 实例,此方法不支持 EFCore Where 查询</param> | |
| /// <param name="comparison"><see cref="StringComparison"/> 实例,此方法不支持 EFCore Where 查询</param> | |
| /// <returns></returns> |
Copilot
AI
Dec 30, 2025
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.
The method name has a typo: "ContainsWidthComparison" should be "ContainsWithComparison". "Width" refers to dimensions/size, while "With" is the correct preposition indicating inclusion.
Copilot
AI
Dec 30, 2025
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.
The method name has a typo: "ContainsWidthComparison" should be "ContainsWithComparison". "Width" refers to dimensions/size, while "With" is the correct preposition indicating inclusion.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
@@ -56,15 +56,17 @@ public static FilterKeyValueAction ToFilter(this QueryPageOptions option) | |
| /// 将 QueryPageOptions 过滤条件转换为 where 条件中的参数 <see cref="Func{T, TResult}"/>"/> 推荐 Linq 使用 | ||
|
||
| /// </summary> | ||
| /// <param name="option"></param> | ||
| /// <param name="comparison"><see cref="StringComparison"/> 实例,此方法不支持 EFCore Where 查询</param> | ||
| /// <returns></returns> | ||
| public static Func<TItem, bool> ToFilterFunc<TItem>(this QueryPageOptions option) => option.ToFilterLambda<TItem>().Compile(); | ||
| public static Func<TItem, bool> ToFilterFunc<TItem>(this QueryPageOptions option, StringComparison? comparison = null) => option.ToFilterLambda<TItem>(comparison).Compile(); | ||
|
|
||
| /// <summary> | ||
| /// 将 QueryPageOptions 过滤条件转换为 <see cref="Expression{TDelegate}"/> 表达式"/> 推荐 EFCore <see cref="IQueryable"/> 使用 | ||
|
||
| /// </summary> | ||
| /// <param name="option"></param> | ||
| /// <param name="comparison"><see cref="StringComparison"/> 实例,此方法不支持 EFCore Where 查询</param> | ||
| /// <returns></returns> | ||
| public static Expression<Func<TItem, bool>> ToFilterLambda<TItem>(this QueryPageOptions option) => option.ToFilter().GetFilterLambda<TItem>(); | ||
| public static Expression<Func<TItem, bool>> ToFilterLambda<TItem>(this QueryPageOptions option, StringComparison? comparison = null) => option.ToFilter().GetFilterLambda<TItem>(comparison); | ||
|
|
||
| /// <summary> | ||
| /// 是否包含过滤条件 | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,30 @@ namespace UnitTest.Extensions; | |||||
|
|
||||||
| public class LambadaExtensionsTest : BootstrapBlazorTestBase | ||||||
| { | ||||||
| [Fact] | ||||||
| public void GetFilterFunc_Comparison() | ||||||
| { | ||||||
| var filter = new FilterKeyValueAction() | ||||||
| { | ||||||
| FieldKey = "Name", | ||||||
| FilterAction = FilterAction.Contains, | ||||||
| FieldValue = "T" | ||||||
| }; | ||||||
|
|
||||||
| var foos = new Foo[] | ||||||
| { | ||||||
| new() { Name = "Test1" }, | ||||||
| new() { Name = "test2" }, | ||||||
| }; | ||||||
|
|
||||||
| var items = foos.Where(filter.GetFilterFunc<Foo>()); | ||||||
| Assert.Single(items); | ||||||
|
|
||||||
| // 忽略大小写 | ||||||
|
||||||
| // 忽略大小写 | |
| // Ignore case |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -39,6 +39,11 @@ public void ToFilter_Searches() | |||||
| expected = _foos.Where(predicate); | ||||||
| Assert.Equal(2, expected.Count()); | ||||||
|
|
||||||
| // 忽略大小写 | ||||||
|
||||||
| // 忽略大小写 | |
| // Case-insensitive comparison |
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.
Missing return value documentation. The parameter documentation was added, but the <returns> section was removed. Add: /// <returns></returns> to maintain complete API documentation.