Suppose I have:
class Foo {
public int Bar { get; set; }
}
public void SetThree( Foo x )
{
Action<Foo, int> fnSet = (xx, val) => { xx.Bar = val; };
fnSet(x, 3);
}
How can I rewrite the definition of fnSet using an expression trees, e.g.:
public void SetThree( Foo x )
{
var assign = *** WHAT GOES HERE? ***
Action<foo,int> fnSet = assign.Compile();
fnSet(x, 3);
}
Here’s an example.
Prints out “3”.