Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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
C# 表达式树-不包含_C#_Expression Trees - Fatal编程技术网

C# 表达式树-不包含

C# 表达式树-不包含,c#,expression-trees,C#,Expression Trees,我需要创建一个表达式来搜索一个字符串而不包含另一个字符串。我能够为contains方法创建它: return Expression.Call(firstOrDefaultCall, typeof(string).GetMethod("Contains"), Expression.Constant(text)); 如何将其转换为“不包含”?您通常如何编写它 var stringValue = "foo" var result = !stringValue.

我需要创建一个表达式来搜索一个字符串而不包含另一个字符串。我能够为contains方法创建它:

return Expression.Call(firstOrDefaultCall, typeof(string).GetMethod("Contains"), Expression.Constant(text));

如何将其转换为“不包含”?

您通常如何编写它

var stringValue = "foo"
var result = !stringValue.Contains("o");
注意逻辑求反运算符
包含()之前
。这是你唯一缺少的部分。要在构建表达式时对布尔值求反,请使用
expression.Not()

不要落入使用Expression.Negate()的陷阱。这是一个算术求反运算,算术求反的例子:

var negatedPi = Math.PI * -1;

?不,请参阅已接受的答案,您应该使用表达式,而不是方法
var negatedPi = Math.PI * -1;