views:

63

answers:

1

I have a generic class HierarchicalBusinessObject. In the constructor of the class I pass a lambda expression that defines a selector to a field of TModel.

protected HierarchicalBusinessObject
    (Expression<Func<TModel,string>> parentSelector)

A call would look like this, for example:

public class WorkitemBusinessObject : 
    HierarchicalBusinessObject<Workitem,WorkitemDataContext>
{
    public WorkitemBusinessObject() 
       : base(w => w.SuperWorkitem, w => w.TopLevel == true)
    { }
}

I am able to use the selector for read within the class. For example:

sourceList.Select(_parentSelector.Compile()).Where(...

Now I am asking myself how I could use the selector to set a value to the field. Something like selector.Body() .... Field...

A: 
Henrik
I understand your proposal. Thanks. But then I have to pass two expressions, one for setting and the second for getting. This is somewhat redundant, since it is the same field. I was hoping to pass just "this is the field" and implement the setter and getter generically.
Frank Michael Kraft
By the way I am using Expressions, because I need them for Linq query construction (entity framework).
Frank Michael Kraft