查询状态机中可能的未来状态的当前状态

发布于 2024-12-23 03:57:37 字数 126 浏览 1 评论 0原文

我正在寻找一种方法来查询状态机中的状态,以找出该状态的可能目的地。我知道一种选择是解析 Xaml 以获取我需要的信息。还有别的办法吗?可能通过查询 .NET 代码中的状态对象?

目标是减少存储状态转换的业务逻辑的位置数量。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟若柳尘 2024-12-30 03:57:38

我今天也遇到了这个问题 - 我以为 mperrenoud03 的代码可以解决它,但可惜它在 .NET 4.5 RC 下对我不起作用。原因是它反映了内部/私有类型System.Activities.Statements.InternalState而不是System.Activities.Statements.State

InternalState 对象有一个 Transitions 集合,我可能可以通过进一步的反思来获得它......但我觉得这让我通过了气味测试。

我发现到目前为止有效的解决方案是这个 NuGet: http://nuget.org/packages/ Microsoft.Activities.Extensions。它有一个名为 StateMachineStateTracker 的 WF 扩展。您可以随时向其询问当前的 StateMachine 及其 Transitions 集合。

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.

沉睡月亮 2024-12-30 03:57:38

是的,你可以。如果发出以下语句,您可以从自定义活动获取状态机本身。

this.GetType().GetProperty("Parent",
    System.Reflection.BindingFlags.NonPublic |
        System.Reflection.BindingFlags.Instance).GetValue(this, null)

然后,状态机对象上有一个名为 Transitions 的属性——每个 Transition 都有一个 To 属性,指示它们转换到哪个 State。

顺便说一句,您还可以从该对象中获取触发器和条件! :)

我希望这有帮助!

Yes, you can. If you issue the following statement you can get the state machine itself from a custom activity.

this.GetType().GetProperty("Parent",
    System.Reflection.BindingFlags.NonPublic |
        System.Reflection.BindingFlags.Instance).GetValue(this, null)

Then on the state machine object is a property named Transitions -- each Transition has a To property incidating what State they transition to.

Incidentally you can also grab the Trigger and Condition from that object! :)

I hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文