Machinery is a minimalistic .NET library for dealing with state machines.
Implement IState<C, E, S>
by your base state:
public interface IState<in TContext, in TEvent, TState>
{
bool TryCreateNewState(TContext context, TEvent ev, out TState newState);
void OnExiting(TContext context, TEvent ev, TState newState);
void OnExited(TContext context, TEvent ev, TState newState);
void OnRemain(TContext context, TEvent ev);
void OnEntering(TContext context, TEvent ev, TState oldState);
void OnEntered(TContext context, TEvent ev, TState oldState);
}
MyContext context = …;
MyState initialState = …;
var stateMachine = StateMachine<Event>.Create(context, initialState);
MyEvent ev = …;
_ = stateMachine.TryProcessEvent(ev);
MyState currentState = stateMachine.CurrentState;
The icon is designed by OpenMoji — the open-source emoji and icon project. License: CC BY-SA 4.0.