本文整理汇总了C#中StateMachine.Valid方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.Valid方法的具体用法?C# StateMachine.Valid怎么用?C# StateMachine.Valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMachine
的用法示例。
在下文中一共展示了StateMachine.Valid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Order
public Order()
{
// You could also subclass StateMachine<T> and encapsulate these details
Status = new StateMachine<OrderState>(OrderState.Created);
// Only transitions defined here are valid. Alternatively, you could call
// ValidAny() to allow all state transitions
Status.Valid(OrderState.Created, OrderState.Ordered);
Status.Valid(OrderState.Ordered, new[] { OrderState.Cancelled, OrderState.Preparing });
Status.Valid(OrderState.Preparing, OrderState.Shipped);
Status.Transitions.Enter_Shipped((Action)delegate()
{
Debug.WriteLine("Order Shipped!");
});
// Enter transition events
Status.DoWhenAny((status) =>
{
// Useful for writing a transition history log
Debug.WriteLine("[{0}] Order Status => {1}", (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds, status);
});
// Or DoFollowingAny() for exit transitions
}
示例2: BuildStoplight
private StateMachine<StoplightState> BuildStoplight(StoplightState initalState)
{
var light = new StateMachine<StoplightState>(initalState);
light.Valid(StoplightState.Green, StoplightState.Yellow);
light.Valid(StoplightState.Yellow, StoplightState.Red);
return light;
}
示例3: BuildUp
public static void BuildUp(TestContext ctx)
{
light = new StateMachine<StoplightState>(StoplightState.Green);
light.Valid(StoplightState.Green, StoplightState.Yellow);
light.Valid(StoplightState.Yellow, StoplightState.Red);
}