Usually I find it worthwhile to code a lambda expression that does what I want, and then see what the C # compiler does with it.
So this code:
Expression<Func<bool,bool>> func = x => !x;
Compiled to:
ParameterExpression expression2; Expression<Func<bool, bool>> expression = Expression.Lambda<Func<bool, bool>>(Expression.Not( expression2 = Expression.Parameter(typeof(bool), "x")), new ParameterExpression[] { expression2 });
(Apologies for formatting - it's hard to figure out what to do about it.)
This is decompiled with Reflector, but with its โoptimizationโ installed on .NET 2.0, to avoid using lambda syntax.
Once you pass the trash, you will see it with Expression.Not . && uses Expression.AndAlso and || uses Expression.OrElse .
source share