I think this does what you are asking for: Expression> Combined { get { var entity = Expression. Parameter(typeof(TEntity)); var pa = Expression. Invoke(PropertyAccessor, entity); var te = Expression.
Invoke(TestExpression, pa); return (Expression>) Expression. Lambda(te, entity); } } I tested this and it works as I would expect However, re-reading your original question (before my edits), I am beginning to get the impression that you asked the wrong question and that you probably don’t need expression trees. If all you need is functions then you can use them without Expression : private Func PropertyAccessor { get; set; } private Func TestExpression { get; set; } private Func Combined { get { return entity => TestExpression(PropertyAccessor(entity)); } } Example of use: Set up the original functions PropertyAccessor = entity => GenerateResult(entity); TestExpression = result => result.IsCool(); // This stores a reference to the combined function var fn = Combined; // This actually evaluates the function bool isCool = fn(myEntity); // Alternatively, you could evaluate the function directly, without the variable bool isCool = Combined(myEntity).
I think this does what you are asking for: Expression> Combined { get { var entity = Expression. Parameter(typeof(TEntity)); var pa = Expression. Invoke(PropertyAccessor, entity); var te = Expression.
Invoke(TestExpression, pa); return (Expression>) Expression. Lambda(te, entity); } } I tested this and it works as I would expect. However, re-reading your original question (before my edits), I am beginning to get the impression that you asked the wrong question and that you probably don’t need expression trees.
If all you need is functions, then you can use them without Expression: private Func PropertyAccessor { get; set; } private Func TestExpression { get; set; } private Func Combined { get { return entity => TestExpression(PropertyAccessor(entity)); } } Example of use: // Set up the original functions PropertyAccessor = entity => GenerateResult(entity); TestExpression = result => result.IsCool(); // This stores a reference to the combined function var fn = Combined; // This actually evaluates the function bool isCool = fn(myEntity); // Alternatively, you could evaluate the function directly, without the variable bool isCool = Combined(myEntity).
Wow thank you for this working answer. I got over my head by diving into expression. I guess that looking at ASP.NET MVC code makes you think that Expression are needed everywhere.
– Pierre-Alain Vigeant Aug 19 '10 at 2:06 Marc Gravell has a great article on InfoQ regarding how and why you should use Expression and some good concrete examples. Infoq.Com/articles/expression-compiler – David Robbins Aug 24 '10 at 21:57.
When using Expression. TPropertyResult is a string during my test. I tried using Expression.
Call or Expression.Invoke. What should I use?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.