I have two similar functions I hope to refactor to remove duplication:
IEnumerable<TotalType> GetTotalForMonths(string id, DateTime lastTotalDate)
{
for (int i = 0; lastTotalDate.AddMonths(i + 1) <= DateTime.Now; i++)
{
var totalStartDate = new DateTime(lastTotalDate.AddMonths(i).Year, lastTotalDate.AddMonths(i).Month, 1);
var totalEndDate = totalStartDate.AddMonths(1);
var total = this.GetTotal(id, totalStartDate, totalEndDate);
yield return new TotalType(id, total, new TimeInterval(totalStartDate, totalEndDate));
}
}
The other does the same thing for days. I hope to pass in a delegate to generic-ize the particular duration (days, months, etc). I tried passing in Func<DateTime, DateTime> addTime
, which works well, except that I don't want to specify addTime's arg value.
Suggestions?