C#C
C#4y ago
Alex Frost

Pass DateTime.Add function as parameter

I have a switch statement that will call a generation function so I don't have to loop for every scenario:
switch (E.RepMode)
{
    case "daily":
        repeats.Add(GenerateRepeats(entry.DateStart, entry.DateEnd, 1, DateTime.AddDays));
        break;
    case "weekly":
        break;
    case "monthly":
        break;
    case "yearly":
        break;
}

The function needs to be something like this:
public List<EntryRepeat> GenerateRepeats(DateTime start, DateTime end, int interval, Func<double, DateTime> f)
{
    do
    {

    }
    while (true);
}

However I'm not able to pass the function being non-static. Is there a way to achieve this or a better approach?
Was this page helpful?