Created
June 16, 2012 00:38
-
-
Save eugeniop/2939379 to your computer and use it in GitHub Desktop.
StateMachine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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