public Example() { // create the schedule from which we will get it's description var schedule = new WeeklySchedule() { Frequency = 2, Monday = true, Friday = true }; // one-liner print SimplePrint(schedule); // set up a custom formatter and print the schedule, returning the formatter var formatter = AdvancedPrint(schedule); // print an entire list of schedules using the custom formatter BulkPrint(formatter); }
private void SimplePrint(WeeklySchedule schedule) { // create the standard formatter that will be used to generate the schedule description Console.WriteLine(new ScheduleFormatter().Format(schedule)); }
/// <summary> /// Allow 2 weeks to show up as "Fortnightly", otherwise return the base implementation of a week description. /// </summary> public override string Format(WeeklySchedule s) { if (s.Frequency == 2) return "Fortnightly"; // to be complete this should output which days that occur fortnightly return base.Format(s); }
private ISchedule Generate(SqlDataReader reader) { ISchedule result; if (!IsDBNull(reader, "sd.Id")) result = new DailySchedule(); else if (!IsDBNull(reader, "sw.Id")) { var week = new WeeklySchedule(); week.Monday = GetBoolean(reader, "Monday"); week.Tuesday = GetBoolean(reader, "Tuesday"); week.Wednesday = GetBoolean(reader, "Wednesday"); week.Thursday = GetBoolean(reader, "Thursday"); week.Friday = GetBoolean(reader, "Friday"); week.Saturday = GetBoolean(reader, "Saturday"); week.Sunday = GetBoolean(reader, "Sunday"); result = week; } else if (!IsDBNull(reader, "sm.Id")) result = new MonthlySchedule(); else if (!IsDBNull(reader, "smd.Id")) result = new MonthlyDaySchedule(); else if (!IsDBNull(reader, "sy.Id")) result = new YearlySchedule(); else return null; result.Frequency = GetInt32(reader, "Frequency"); return result; }