コード例 #1
0
        public static void Run()
        {
            Console.Clear();

            // Create a person state machine instance, and return it, set in some start state :
            var  joe = new Person().Start(Status.Unborn);
            bool done;

            // Holds iff the chosen start state isn't a final state :
            System.Diagnostics.Debug.Assert(joe != null, "The chosen start state is a final state!");

            // Trigger state transitions with or without the (optional) DateTime argument :
            done =
                (
                    joe.
                    MoveNext("born", new DateTime(1963, 2, 1)).     // equivalent to : joe.MoveNext("Birth", ...)
                    MoveNext("graduate", new DateTime(1980, 6, 5)).
                    MoveNext("work", new DateTime(1981, 7, 6)).
                    MoveNext("Lay off", new DateTime(1982, 8, 7)). // equivalent to : joe.MoveNext("laid off", ...)
                    MoveNext("work", new DateTime(1983, 9, 8)).
                    MoveNext("retire")                             // MoveNext(...) returns null iff joe.IsFinal == true
                    == null
                );

            Console.WriteLine();
            Console.WriteLine("Is Joe's state '{0}' a final state? {1}", joe.Value, done);

            Console.WriteLine();
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }