Create an Action<T> to "set" a property, when I am provided with the LINQ Expression for the "get"

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2011-01-04T17:19:21Z Indexed on 2011/01/04 18:53 UTC
Read the original article Hit count: 137

Filed under:
|

I'd like to be able to generate a compiled expression to set a property, given the lambda expression that provides the "get" method for a property.

Here's what I'm looking for:

public Action<int> CreateSetter<T>(Expression<Func<T, int>> getter)
{
    // returns a compiled action using the details of the getter expression tree, or null
    // if the write property is not defined.
}

I'm still trying to understand the various types of Expression classes, so if you can point me in the right direction that would be great.

© Stack Overflow or respective owner

Related posts about c#

Related posts about expression-trees