I’ve learned to manipulate Dynamic lambda expressions with the Expression class.
However, the lambda expression used in a ForEach method (LINQ) seems a little different since it’s an assign.
For exemple, doing this :
myList.ForEach(x => x.Status = "OK") ;
will update the Status property of each object in the myList list.
How to accomplish it using Expression object? I didn’t find any method in Expression to set a property… Is it used only for retrieving properties values ?
Assignment does exist in expression trees (see
Expression.Assign) as of .NET 4 (where it’s used to supportdynamic), but it’s not supported by the C# compiler, which still only supports genuine “expressions” for lambda expression conversions to expression trees.