public static void ShowExample() { Calendar cal = new Calendar(); #region Проверка календаря по умолчанию ShowDayPeriod(cal, new DateTime(2017, 02, 13), 14); Log(); Console.ReadKey(); #region Добавляем выходной день Log("Добавляем выходной день"); cal.AddHoliday(new DateTime(2017, 02, 23)); ShowDayPeriod(cal, new DateTime(2017, 02, 13), 14); #endregion Log(); Console.ReadKey(); #region Добавляем рабочий день Log("Добавляем рабочий день"); cal.RemoveHoliday(new DateTime(2017, 02, 26)); ShowDayPeriod(cal, new DateTime(2017, 02, 13), 14); #endregion Log(); Console.ReadKey(); #region Добавляем ошибки Log("Добавляем ошибки"); cal.RemoveHoliday(new DateTime(2017, 02, 26)); ShowDayPeriod(cal, new DateTime(2017, 02, 13), 14); #endregion #endregion #region Полиморфизм методов Calendar cal1 = new Calendar(); Calendar cal2 = new USCalendar(); Log(cal1.Name); Log(cal2.Name); Log(((USCalendar)cal2).Name); #endregion #region Скрытие метода ExA exref = new ExA(); Log($"ExA.ShowMessage: {exref.ShowMessage()}"); // -> ExA exref = new ExB(); Log($"ExB.ShowMessage: {exref.ShowMessage()}"); // -> ExB exref = new ExC(); Log($"ExC.ShowMessage: {exref.ShowMessage()}"); // -> ExA exref = new ExD(); Log($"ExD.ShowMessage: {exref.ShowMessage()}"); // -> ExA ExC exref2 = (ExC)exref; Log($"ExD.ShowMessage: {exref2.ShowMessage()}"); // -> ExD #endregion //функция вывода в консоль void Log(string inMes = "") { Console.WriteLine(inMes); } }
/// <summary> /// Объединение календарей /// </summary> /// <param name="cal1"></param> /// <param name="cal2"></param> /// <returns></returns> public static Calendar operator +(Calendar cal1, Calendar cal2) { Calendar rescal = new Calendar(); rescal.addedHolidays.AddRange(cal1.addedHolidays); rescal.removedHolidays.AddRange(cal1.removedHolidays); foreach (DateTime dt in cal2.addedHolidays) { rescal.AddHoliday(dt); } foreach (DateTime dt in cal2.removedHolidays) { rescal.RemoveHoliday(dt); } return(rescal); }