A context-based state machine in C#