Skip to content

qbit86/machinery

Repository files navigation

Machinery

Machinery version

Machinery is a minimalistic .NET library for dealing with state machines.

Usage

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;

License

License

The icon is designed by OpenMoji — the open-source emoji and icon project. License: CC BY-SA 4.0.

About

Minimalistic state machine

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages