Search code examples
c#linqlinq-to-objectsexpression-treesstate-machine

Can LINQ expression classes implement the observer pattern instead of deferred execution?


We have issues within an application using a state machine. The application is implemented as a windows service and is iteration based (it "foreaches" itself through everything) and there are myriads of instances being processed by the state machine.

As I'm reading the MEAP version of Jon Skeets book "C# in Depth, 2nd ed", I'm wondering if I can change the whole thing to use linq expression instances so that guards and conditions are represented using expression trees.

We are building many applications on this state machine engine and would probably greatly benefit from the new Expression tree visualizer in VS 2010

Now, simple example. If I have an expression tree where there is an OR Expression condition with two sub nodes, is there any way that these can implement the observer pattern so that the expression tree becomes event driven? If a condition change, it should notify its parent node (the OR node). Since the OR node then changes from "false" to "true", then it should notify ITS parent and so on.

I love the declarative model of expression trees, but the deferred execution model works in opposite direction of the control flow if you want event based "live" conditions.

Am I off on a wild goose chase here? Or is there some concept in the BCL that may help me achieve this?


Solution

  • It sounds like the new Reactive Framework may be of interest to you:

    Rx is a library for composing asynchronous and event-based programs using observable collections.