Is it possible to observe a lambda statement block?

Dec 31, 2009 at 2:43 AM

Hi Thomas

Is there a workaround so that Obtics can observe a lambda statement block?


       static Func<int> func;

       func = () => { logic-here-that-references-observable-properties-queries-etc; return result; };     // something too long to write as a lambda expression

       ExpressionObserver.Execute(() => func());

I assume the issue is that it's not possible to automatically create an expression tree from a lambda statement block?

Many thanks.

Dec 31, 2009 at 8:37 AM


Unfortunately it is not possible under Framework 3.5 to create a lambda expression of a lambda function that contains a statement block.

It is possible though to reference other  expressions-made-observable from lambda expressions. That way you can partition your complex expression over multiple expressions. Like:

static Func<IValueProvider<int>> First = ExpressionObserver.Compile( () => 'expression-returning-an-int' );

static Func<IValueProvider<int>> Second = ExpressionObserver.Compile( ()=> First().Value * First().Value + 1 ); //nests observable lambda function stored in First



Jan 1, 2010 at 8:38 AM

Hi Thomas

That's a good idea.

To overcome the .NET framework limitation, I'll try breaking down my (complex) lambda statement blocks into several simpler lambda expressions so that they can be individually observed by obtics.