Witam,
Próbuje wykorzystać extension method.
Wrzuciłem swoją klasę jak poniżej i dostaje error:
Error 1 Extension method must be defined in a top level static class; DateTimeExtensions is a nested class
Jest w stanie mi to ktoś wyjaśnić? Rozumiem czemu taki wyskakuje ale nie rozumiem w czym niby tak klasa jest zagnieżdżona
namespace Scheduler.Controllers
{
public class SchedulerController : Controller
{
...
}
public static class DateTimeExtensions
{
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
int diff = dt.DayOfWeek - startOfWeek;
if (diff < 0)
{
diff += 7;
}
return dt.AddDays(-1 * diff).Date;
}
}
}