diff --git a/src/Stateless/StateMachine.cs b/src/Stateless/StateMachine.cs index a28c5f48..b683bfd2 100644 --- a/src/Stateless/StateMachine.cs +++ b/src/Stateless/StateMachine.cs @@ -147,6 +147,17 @@ public IEnumerable> GetDetailedPermittedTrigger .Select(trigger => new TriggerDetails(trigger, _triggerConfiguration)); } + /// + /// Gets any triggers for the current state that are not permissible, and the descriptions + /// of the unmet trigger conditions associated with them. + /// + /// + /// + public IEnumerable> GetTriggersWithUnmetConditions(params object[] args) + { + return CurrentRepresentation.GetTriggersWithUnmetGuardConditions(args); + } + StateRepresentation CurrentRepresentation { get diff --git a/src/Stateless/StateRepresentation.cs b/src/Stateless/StateRepresentation.cs index 6c306553..2d8c762e 100644 --- a/src/Stateless/StateRepresentation.cs +++ b/src/Stateless/StateRepresentation.cs @@ -330,6 +330,26 @@ public IEnumerable GetPermittedTriggers(params object[] args) return result; } + public IEnumerable> GetTriggersWithUnmetGuardConditions(params object[] args) + { + List> unmetConditions = new List>(); + + var behaviours = TriggerBehaviours.Values.SelectMany(x => x); + foreach (var triggerBehaviour in behaviours) + { + if (triggerBehaviour.GuardConditionsMet(args)) + continue; + + var conditions = triggerBehaviour.UnmetGuardConditions(args); + unmetConditions.Add(new Tuple(triggerBehaviour.Trigger, conditions.ToArray())); + } + + if (Superstate != null) + unmetConditions.AddRange(Superstate.GetTriggersWithUnmetGuardConditions(args)); + + return unmetConditions; + } + internal void SetInitialTransition(TState state) { InitialTransitionTarget = state;