.NET C# setting the value of a field defined by a lambda selector

Posted by Frank Michael Kraft on Stack Overflow See other posts from Stack Overflow or by Frank Michael Kraft
Published on 2010-04-16T07:03:55Z Indexed on 2010/04/16 7:33 UTC
Read the original article Hit count: 257

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...

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET