Tôi có lớp sau đây:Tại sao Expression.And đại diện cho "&" nhưng không "&&"
public class Test
{
public string Text { get; set; }
public int Number { get; set; }
}
Và tôi tạo ra và cây Biểu hiện của loại Expression<Func<Test, bool>>
trên lớp này. Khi tôi làm điều đó như thế này:
Expression<Func<Test, bool>> predicate1 = x => x.Text.Length > 5 && x.Number > 0;
tôi có được cái nhìn debug sau:
.Lambda #Lambda1<System.Func`2[NHLinqTest.Test,System.Boolean]>(NHLinqTest.Test $x) {
($x.Text).Length > 5 && $x.Number > 0
}
lưu ý: có một &&
cho và tác.
Khi tôi làm điều đó như thế này:
var y = Expression.Parameter(typeof(Test));
var predicate2 = Expression.And(
Expression.GreaterThan(
Expression.Property(Expression.Property(y, "Text"), "Length"),
Expression.Constant(5)),
Expression.GreaterThan(
Expression.Property(y, "Number"),
Expression.Constant(0)));
tôi có được cái nhìn debug sau:
($var1.Text).Length > 5 & $var1.Number > 0
Lưu ý: có &
cho và tác. Tại sao tôi nhận được &
trong trường hợp thứ hai? Cách sửa đổi predicate2
để nhận &&
thay vì &
?
Cảm ơn bạn trước!