I am new to System.Linq.Expresions and I am trying to figure out what is wrong with this code:
var mc = new MyClass(); ParameterExpression value = Expression.Parameter(typeof(object), "value"); ParameterExpression xParam = Expression.Parameter(typeof(MyClass), "x"); Expression<Func<MyClass, object>> e = x => x.Val; BlockExpression block = Expression.Block(new[] { xParam, value }, Expression.Assign(e.Body, value)); Expression.Lambda<Action<MyClass, object>>(block, xParam, value).Compile()(mc, 5);
I just want to create something like mc.Val = 5, assuming MyClass and the object parameter are lambda parameters (I don't want to use closure)
source share