I’m looking for a way to query a state in a state machine to find out what the possible destinations are for that state. I know that one option is to parse the Xaml for the information that I need. Is there another way? Possibly by querying the state object in .NET code?
The goal is to decrease the number of places that the business logic for the state transitions is stored.
I faced this question too today – I thought mperrenoud03’s code would solve it, but alas it didn’t work for me under .NET 4.5 RC. The reason is that it reflected an internal/private type System.Activities.Statements.InternalState rather than System.Activities.Statements.State.
The InternalState object had a Transitions collection, which I could probably obtain by further reflection … but I felt this took me way past the smell test.
A solution I found which is working so far is this NuGet: http://nuget.org/packages/Microsoft.Activities.Extensions. It has a WF Extension called StateMachineStateTracker. At any time, you can ask it for the current StateMachine, and its collection of Transitions.