how to set value for this property public Expression<Action<Controller>> Action { get; set; }
i have a class that has this property
public Expression<Action<Controller>> Action { get; set; }
how to set it开发者_如何学JAVA's value for example:
var x = new MyClass{
Action = What_To_Write_here
}
in same way as simple Action<Controller>
var x = new MyClass{
Action = controller => controller.DoSomething()
}
To expand on Yurec's answer, lambdas provide syntactic support for both delegates and expressions. The compiler will usually be able to infer which is needed based on context. (As Yurec notes, this is the case for you.) So a lambda assigned to some delegate can be assigned to an expression wrapping the same delegate type.
精彩评论