dotnet-state-machine / stateless

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

Trigger a state that doesn't exist, CanFire API is allowed? #486

Open BAI-HANK opened 2 years ago

BAI-HANK commented 2 years ago

Trigger a state that doesn't exist, CanFire API is allowed, FireAsync API doesn't throw an exception I think it's a little illogical, after _machine. PermittedTriggers , obtaining target state available Triggers,then an exception is throwning, why not CanFire should be told that not allowed, then In FireAsync API throw an exception

   // "null"  is not exist state
   _machine.Configure(State.A.ToString()) .Permit(Trigger.EB.ToString(), "null");

  if (_machine.CanFire(Trigger.EB.ToString())) {
          await bar._machine.FireAsync(Trigger.EB.ToString());
          if (_machine.PermittedTriggers == null) continue;
          foreach (var machinePermittedTrigger in ._machine.PermittedTriggers) {
            Console.WriteLine("can trigger:" + machinePermittedTrigger);
          }
  }