当前位置: 首页>>代码示例>>C#>>正文


C# StateMachine.Valid方法代码示例

本文整理汇总了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
        }
开发者ID:jongalloway,项目名称:statemachine,代码行数:25,代码来源:OrderTests.cs

示例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;
        }
开发者ID:brandonc,项目名称:statemachine,代码行数:8,代码来源:FinalStateTests.cs

示例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);
 }
开发者ID:brandonc,项目名称:statemachine,代码行数:6,代码来源:FinalStateTests.cs


注:本文中的StateMachine.Valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。