简体   繁体   English

即使添加了明确的false语句,PredicateBuilder仍然为true

[英]PredicateBuilder is still true even after adding explicit false statement

I have the following statement. 我有以下声明。

var search = PredicateBuilder.True<SomeType>();
search.And(f => false);

// Still the "search" variable value is: {f => true}.

At first, I was trying an expression; 起初,我正在尝试一种表达方式; nothing succeeded, so I tried this "false" instead. 没有成功,因此我尝试使用此“ false”。 No matter what I did, it's still the same. 不管我做什么,都还是一样。 What is happening? 怎么了?

PredicateBuilder methods don't mutate the expression (they couldn't, as expression trees are immutable) - you need to use the return value: PredicateBuilder方法不会更改表达式(因为表达式树是不可变的,因此无法更改)-您需要使用返回值:

var search = PredicateBuilder.True<SomeType>();
search = search.And(f => false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PredicateBuilder之间的区别 <True> 和PredicateBuilder <False> ? - Difference between PredicateBuilder<True> and PredicateBuilder<False>? 如果语句的计算结果为false,但仍然分支,就好像它是真的一样 - If statement evaluates to false but still branches as if it was true 即使在CallBase = true / false之后,原始方法仍会在Moq中被调用 - Original method still getting called in Moq even after CallBase = true/false 即使if语句为true,函数也会返回false - Functions returns false even when the if statement is true 布尔 OR 语句返回 FALSE,即使其中一侧为 TRUE - Boolean OR statement returns FALSE even though one of the sides is TRUE PredicateBuilder.New vs PredicateBuilder.True - PredicateBuilder.New vs PredicateBuilder.True LINQ PredicateBuilder以PredicateBuilder.True &lt;&gt;开头的多个OR - LINQ PredicateBuilder multiple OR starting with PredicateBuilder.True<> 假 if 语句仍然执行 - False if-statement still executes if/else 语句返回假,即使条件应该为真。 (C#) - If/else statement is returning false, even though the condition should be true. (C#) 模拟了一个返回 true 的方法仍然返回 false - Mocked a method to return true still returns false
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM