【发布时间】:2011-10-07 22:53:10
【问题描述】:
假设我有:
class Foo {
public int Bar { get; set; }
}
public void SetThree( Foo x )
{
Action<Foo, int> fnSet = (xx, val) => { xx.Bar = val; };
fnSet(x, 3);
}
如何使用表达式树重写 fnSet 的定义,例如:
public void SetThree( Foo x )
{
var assign = *** WHAT GOES HERE? ***
Action<foo,int> fnSet = assign.Compile();
fnSet(x, 3);
}
【问题讨论】:
-
作为警告,您至少需要 .Net 4.0。
标签: c# linq .net-4.0 expression-trees