我需要在我的 .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 中是可行的方法。
关于c# - .NET 无状态多重 PermitIf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56458459/