@@ -8,11 +8,17 @@ namespace FiniteStateMachine;
88public sealed class StateConfiguration < TState , TTrigger > where TTrigger : Enum
99{
1010 private readonly TState _state ;
11+
12+ private readonly List < Action > _entryActions ;
13+ private readonly List < Action > _exitActions ;
14+
15+ internal IReadOnlyList < Action > EntryActions => _entryActions ;
16+ internal IReadOnlyList < Action > ExitActions => _exitActions ;
1117
1218 /// <summary>
1319 /// Gets the transitions defined for the current state.
1420 /// </summary>
15- internal Dictionary < TTrigger , TState > Transitions { get ; } = new ( ) ;
21+ internal Dictionary < TTrigger , TransitionOption < TTrigger , TState > > Transitions { get ; } = new ( ) ;
1622
1723 /// <summary>
1824 /// Initializes a new instance of the <see cref="StateConfiguration{TState, TTrigger}"/> class.
@@ -21,6 +27,14 @@ public sealed class StateConfiguration<TState, TTrigger> where TTrigger : Enum
2127 internal StateConfiguration ( TState state )
2228 {
2329 _state = state ;
30+ _entryActions = new List < Action > ( ) ;
31+ _exitActions = new List < Action > ( ) ;
32+ }
33+
34+ internal void ClearActions ( )
35+ {
36+ _entryActions . Clear ( ) ;
37+ _exitActions . Clear ( ) ;
2438 }
2539
2640 /// <summary>
@@ -30,6 +44,19 @@ internal StateConfiguration(TState state)
3044 /// <returns>A configuration object to setup the transition.</returns>
3145 public TransitionConfiguration < TState , TTrigger > On ( TTrigger trigger )
3246 {
47+
3348 return new TransitionConfiguration < TState , TTrigger > ( this , trigger ) ;
3449 }
50+
51+ public StateConfiguration < TState , TTrigger > OnEnter ( Action action )
52+ {
53+ _entryActions . Add ( action ) ;
54+ return this ;
55+ }
56+
57+ public StateConfiguration < TState , TTrigger > OnExit ( Action action )
58+ {
59+ _exitActions . Add ( action ) ;
60+ return this ;
61+ }
3562}
0 commit comments