Example #1
0
        public Example()
        {
            var olympics = new LeapYearSchedule() { Frequency = 1 };

            var inauguration = new DateTime(1896, 1, 1);
            var from = new DateTime(2000, 12, 31);
            var to = new DateTime(2020, 1, 1);
            foreach (var d in olympics.GetOccurrences(inauguration, from).TakeWhile<DateTime>(dt => dt <= to))
                Console.WriteLine(d);

            foreach (var s in Generate())
            {
                Console.WriteLine(s.GetType().Name);

                // the standard formatter doesn't know about our custom schedule, so we can't call
                // ScheduleFormatter.Format(), and it also won't print if we use the visitor pattern
                // LeapYearSchedule.Accept(ScheduleFormatter())
                var standard = new ScheduleFormatter();
                s.Accept(standard);
                Console.WriteLine("Standard: {0}", standard.Description);

                // our extended formatter will print all existing schedules, including our custom one
                var extended = new ExtendedFormatter();
                s.Accept(extended);
                Console.WriteLine("Extended: {0}", extended.Description);
            }
        }
Example #2
0
        public Example()
        {
            var olympics = new LeapYearSchedule()
            {
                Frequency = 1
            };

            var inauguration = new DateTime(1896, 1, 1);
            var from         = new DateTime(2000, 12, 31);
            var to           = new DateTime(2020, 1, 1);

            foreach (var d in olympics.GetOccurrences(inauguration, from).TakeWhile <DateTime>(dt => dt <= to))
            {
                Console.WriteLine(d);
            }

            foreach (var s in Generate())
            {
                Console.WriteLine(s.GetType().Name);

                // the standard formatter doesn't know about our custom schedule, so we can't call
                // ScheduleFormatter.Format(), and it also won't print if we use the visitor pattern
                // LeapYearSchedule.Accept(ScheduleFormatter())
                var standard = new ScheduleFormatter();
                s.Accept(standard);
                Console.WriteLine("Standard: {0}", standard.Description);

                // our extended formatter will print all existing schedules, including our custom one
                var extended = new ExtendedFormatter();
                s.Accept(extended);
                Console.WriteLine("Extended: {0}", extended.Description);
            }
        }