The Bitter Coder Tutorials, Binsor Style, Arrays
namespace BitterCoder.Tutorials.Binsor.Core
{
public class HolidayService
{
private DateTime[] _holidays;
public DateTime[] Holidays
{
get { return _holidays; }
set { _holidays = value; }
}
public bool IsHoliday(DateTime date)
{
if (_holidays != null)
{
DateTime matchDate = date.Date;
foreach (DateTime test in Holidays)
{
if (test.Date.Equals(matchDate))
{
return true;
}
}
}
return false;
}
}
}
static void Main(string[] args)
{
HolidayService holidayService = container.Resolve<HolidayService>();
DateTime xmas = new DateTime(2007, 12, 25);
DateTime newYears = new DateTime(2008, 1, 1);
if (holidayService.IsHoliday(xmas))
Console.WriteLine("merry xmas!");
else
Console.WriteLine("xmas is only for management!");
if (holidayService.IsHoliday(newYears))
Console.WriteLine("happy new year");
else
Console.WriteLine("new year, you haven't done all the work for last year!");
Console.Read();
}
component "holiday.service", HolidayService:
Holidays=(
DateTime(2007,12,24),
DateTime(2007,12,25),
DateTime(2008,1,1)
)