Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 使用表达式执行字符串操作(contains、startwith、…)_Vb.net_String_Linq_Silverlight 4.0_Expression - Fatal编程技术网

Vb.net 使用表达式执行字符串操作(contains、startwith、…)

Vb.net 使用表达式执行字符串操作(contains、startwith、…),vb.net,string,linq,silverlight-4.0,expression,Vb.net,String,Linq,Silverlight 4.0,Expression,我正在尝试为数据概述制作一个通用过滤器,我遇到了一些表达式。在该示例中,一些表达式用于进行比较: return Expression.Equal(left, right); return Expression.GreaterThan(left, right); return Expression.GreaterThanOrEqual(left, right); return Expression.LessThan(left, right); return Expression.LessThanO

我正在尝试为数据概述制作一个通用过滤器,我遇到了一些表达式。在该示例中,一些表达式用于进行比较:

return Expression.Equal(left, right);
return Expression.GreaterThan(left, right);
return Expression.GreaterThanOrEqual(left, right);
return Expression.LessThan(left, right);
return Expression.LessThanOrEqual(left, right);
return Expression.NotEqual(left, right);
对于日期和整数值,我只需要它们,但对于字符串,用户将需要其他筛选功能。所以我想添加“contains and startswith”的可能性。但从“表情”来看,它并没有给我这种可能性。我想添加一些自定义表达式,但我找不到任何与此相关的内容。返回的表达式用于这段代码:

Expression.Call(typeof (Queryable),"Where",new[] {list.ElementType},list.Expression,Expression.Lambda<Func<T, bool>>(exp, new[] {pe}));
Expression.Call(typeof(Queryable),“Where”,new[]{list.ElementType},list.Expression,Expression.Lambda(exp,new[]{pe});
有人有这样做的经验吗


提前感谢。

包含
StartsWith
不是运算符,它们只是类
字符串
的方法,您可以使用
expersion。调用
包含这些方法。

包含
StartsWith
不是运算符,它们只是类的方法
String
您可以使用
expersion。调用
可以包括这些表达式的使用。

您不必添加自定义表达式。只需在实现
IQueryable
的对象的
Where
方法中编写动态linq表达式

像这样:

...
using System.Linq.Dynamic;
...

string searchKeyword = "ant";
IQueryable<Person> collection = GetPersonCollection();
collection.Where(string.Format("FirstName.Contains('{0}')"), searchKeyword);
。。。
使用System.Linq.Dynamic;
...
字符串searchKeyword=“ant”;
IQueryable collection=GetPersonCollection();
其中(string.Format(“FirstName.Contains({0}')”),searchKeyword);

您不必添加自定义表达式。只需在实现
IQueryable
的对象的
Where
方法中编写动态linq表达式

像这样:

...
using System.Linq.Dynamic;
...

string searchKeyword = "ant";
IQueryable<Person> collection = GetPersonCollection();
collection.Where(string.Format("FirstName.Contains('{0}')"), searchKeyword);
。。。
使用System.Linq.Dynamic;
...
字符串searchKeyword=“ant”;
IQueryable collection=GetPersonCollection();
其中(string.Format(“FirstName.Contains({0}')”),searchKeyword);