I have an object that I want to be constructed in such manner:
var foo = new FancyObject(customer, c=>c.Email); //customer has Email property
How should I declare second parameter?
How the code that will access selected property setter/getter will look like?
Upd. There are several entities in the model that has Email property. So probably the signature will looks like:
public FancyObject(Entity holder, Expression<Func<T>> selector)
and the constructor call
var foo = new FancyObject(customer, ()=>customer.Email);
The parameter would be an
Expression<Func<Customer,string>> selector. Reading it can be via flat compile:then you can access
func(customer). Assigning is trickier; for simple selectors your could hope that you can simply decompose to:But more complex expressions would either need a manual tree walk, or some of the 4.0 expression node-types: