Skip to content

Instantly share code, notes, and snippets.

@eugeniop
Created June 16, 2012 00:38
Show Gist options
  • Save eugeniop/2939379 to your computer and use it in GitHub Desktop.
Save eugeniop/2939379 to your computer and use it in GitHub Desktop.
StateMachine
StateMachine<InputEvent,Data> sm = new StateMachine<InputEvent,Data>();
sm.AddState("ONE", null)
.HandleEvent<InputOne>("ONE", (i, ctx, n) => {
Assert.AreEqual(1, i.Id);
Assert.AreEqual("ONE", n);
return n;
},
"Message 1 1")
.HandleEvent<InputTwo>("TWO", (i, ctx, n) => {
Assert.AreEqual("TWO", n);
return n;
},
"Message 1 2");
sm.AddState("TWO", null)
.HandleEvent<InputOne>("ONE", (i, ctx, n) => { return n; }, "Message 2 1")
.HandleEvent<InputTwo>("TWO", (i, ctx, n) => { return n; }, "Message 2 2");
public State<E, P> HandleEvent<I>(string nextState, Func<I, P, string, string> handler, string stateChangeMessage) where I : E
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment