What about methods that don't specifically extend string or DateTime, but rather target or return a string or DateTime? Then you could build some int
and TimeSpan
methods as well, so you can write fluent interfaces like:
DateTime yesterday = 1.Days().Ago();
.
public static TimeSpan Days(this int value)
{
return new TimeSpan(value, 0, 0, 0);
}
public static TimeSpan Hours(this int value)
{
return new TimeSpan(value, 0, 0);
}
public static TimeSpan Minutes(this int value)
{
return new TimeSpan(0, value, 0);
}
//...
.
public static DateTime Ago(this TimeSpan value)
{
return DateTime.Now.Add(value.Negate());
}
public static DateTime FromNow(this TimeSpan value)
{
return DateTime.Now.Add(value);
}