Search code examples
serializationlambdadelegatesxnatombstoning

How do I serialise Lambdas and Event delegates when Tombstoning on the Windows Phone 7?


I've been using the Game State Management sample which has worked so far. I've hit a snag though: when Tombstoning, the screens are serialised; the only trouble is, the MessageBoxScreen has event handlers for Accepted and Cancelled.

What's the best way to serialise these? I did a bit of research on using Expression Trees but this seemed overly complex for what I wanted to do.

How do you serialise these? Or... What alternative approach do you use to save the state of a screen that contains delegates?


Solution

  • I decided against this. I instead persists game flow as a kind of 'flow chart'.

    The flow chart is declared in code and has properties 'LastShape' and 'LastResultFromShape'.

    In my code, I rebuild the flow chart definitions each time, something like this:

    flowChart.AddShape( "ShowSplash" );
    flowChart.AddLine( "MainMenu", ()=>lastResult=="Clicked" || lastResult=="TimedOut");
    
    flowChart.AddShape( "MainMenu");
    flowChart.AddLine( @"ShowOptions", ()=>lastResult=="OptionsClicked");
    flowChar.AddLine( @"ShowSplash", ()=>lastResult==@"TimedOut");
    
    etc.etc.
    

    The flow goes from the top down, so 'AddLine' relates to the last shape added.

    After tombstoning, I just read the last shape and the last result and decide where to go in the flowchart based on that.