gpt4 book ai didi

c# - 在 DynamicLinq 查询中使用扩展方法

转载 作者:行者123 更新时间:2023-11-30 13:04:58 24 4
gpt4 key购买 nike

我想扩展 Telerik RadGrid 的过滤器行为。例如,如果用户使用以下单词“michele”过滤网格,它也应该返回包含“michèle”的行。这在 Telerik RadGrid 中不受开箱即用的支持。因此我为字符串类型写了一个扩展方法:public static bool IsSqlLikeMatch(this string input, string pattern) { [...] }

作为第二步,我像这样替换了 RadGrid 的 FilterExpression:

this.MasterTableView.FilterExpression.Replace( "Contains", "IsSqlLikeMatch" );

但不幸的是,我收到以下错误消息:

No applicable method 'IsSqlLikeMatch' exists in type 'String'

Telerik RadGrid 使用 DynamicLinq。因此我的问题是:“我可以在 DynamicLinq 中使用扩展方法吗”?我该如何做到这一点?

编辑 09/09/2011:我已经联系了 Telerik 支持,这是他们的回答:

Unfortunately you could not extend the dynamic linq functions included into Telerik.Web.UI.dll. So your changes to the DynamicLinq class will not effected the ExpressionParser used internally into the RadControls. However you could try changing the Dynamic Linq library and perform custom filtering by getting the filter expression from the RadGrid parse and pass them to the changed Dynamic Linq class' method and bind the RadGrid to the returned data. I have attached a small sample which demonstrates how to use RadGrid's filter/sort expressions to filter, sort and page through ObjectDataSource.

最佳答案

为了使用扩展方法,您必须为定义扩展方法的类的命名空间设置 using 指令。

因此尝试将您的类放在命名空间中,并为其添加 using

另外,确保这个类被定义为 public static。

关于c# - 在 DynamicLinq 查询中使用扩展方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6652698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com