c# - .NET 无状态多重 PermitIf

标签 c# .net state-machine stateless-state-machine

我需要在我的 .Net Stateless state machine 中为某个状态添加多个守卫.

考虑以下模拟场景。如果满足两个条件,我只能允许从插入到修改:

        _sm.Configure(State.Insert)
            .PermitReentry(Trigger.Insert)
            .PermitIf(Trigger.Modify, State.Modified, Condition1, "Only permitted when condition 1 true")
            .PermitIf(Trigger.Modify, State.Modified, Condition2, "Only permitted when condition 2 true")
            .Permit(Trigger.Cancel, State.Canceled)

在上面的代码中,只有第一个条件被评估。 我也可以将两个条件捆绑到一个条件中,在一个 PermitIf 中传递它,但我不想这样做:

        .PermitIf(Trigger.Modify, State.Modified, BundledCondition, "Only permitted when bundled condition is true")

有没有办法在 dotnet-state-machine 中实现多个守卫?

最佳答案

我认为这是不可能的。特别是在阅读文档中的这个声明之后:

Guard clauses within a state must be mutually exclusive (multiple guard clauses cannot be valid at the same time.)

我想将所有条件捆绑在 only guard 中是可行的方法。

https://github.com/dotnet-state-machine/stateless

关于c# - .NET 无状态多重 PermitIf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56458459/

相关文章:

c# - 构建时出现 Visual Studio 2013 错误

c# - Telerik Radgrid 导出文件名

java - 为什么我的 Java RSA 加密会出现算术异常?

c# - MySQL 和 C#.NET DataGridView、更新、插入和删除

c# - 退出递归函数搜索子目录

java - 用 Java 实现 FSA/FSM 的最佳方法是什么

c# - 避免处理函数的长 switch/if

c# - XNA 中的 ColorMatrix 等效项

c# - 反序列化集合时未调用 Setter

events - 状态机将事件推送到自己的事件队列