Skip to content

Check available transitions #450

@anatoly-kryzhanovsky

Description

@anatoly-kryzhanovsky

I need to have method which return true if transition with specified trigger and parameters available for current state.
because there are parameters i can't use CanFire, so i write following code:

public bool CanApply(TTriggers trigger, params object[] arguments)
{
	if(arguments == null || arguments.Length == 0)
		return StateMachine.CanFire(trigger);
	
	var permittedTriggers = StateMachine.GetPermittedTriggers(arguments);
	return permittedTriggers.Any(x => Equals(x, trigger));
}

and it works perfectly, but not always.

for example i have state machine with following transitions:

  • new -> review, with string parameter (like reason)
  • new -> onprogress with guid parameter (like document id)

now, then i call CanApply method with SendToWork as trigger and Guid as argument the ArgumentException was throwed. Stateless try to convert Guid to string.

i can't find any workaround to get available transition.
The PermittedTriggers property also throw exception (but another - NullReference)

Environment:

  • Platform: .net core 3.1
  • Stateless: 5.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions