dotnet-state-machine / stateless

A simple library for creating state machines in C# code
Other
5.41k stars 746 forks source link

Permit state reentry from dynamic transitions. #571

Closed mclift closed 2 months ago

mclift commented 2 months ago

To address issue #565, this PR restores the pre-v5.15 behavior so that state re-entry is possible when dynamic transitions are used.

Example:

var sm = new StateMachine<State, Trigger>(State.A);
sm.Configure(State.A).PermitDynamic(Trigger.X, () => State.A);
Console.WriteLine($"Initial state: {sm.State}");

// Firing Trigger.X does not cause InvalidOperation to be thrown.
sm.Fire(Trigger.X);
Console.WriteLine($"Final state: {sm.State}");

// Output:
// Initial state: A
// Final state: A