With the power of Extension Methods introduced in C# 3.0, you can design a Fluent Interface that gives the Ruby date syntax mentioned in this article on the beauty of Ruby's readability:
public static class MyExtensions { public static TimeSpan minutes(this int minutes) { return new TimeSpan(0, minutes, 0); } public static DateTime ago(this TimeSpan timeSpan) { return DateTime.Now.Add(timeSpan.Negate()); } }
And now we have a the Ruby-like date syntax (at least for minutes) in C#:
Since the above code would return a DateTime object, here is an example usage:
if (startDate < 20.minutes().ago()) { Console.Out.WriteLine("Started over 20 minutes ago"); }
Remember Me
b, blockquote@cite, em, i, strike, strong, sub, sup, u
Powered by: newtelligence dasBlog 2.3.9074.18820
© Copyright 2013, Troy DeMonbreun
E-mail