Re:The microservices cargo cult
by radicalbyte on Tuesday October 06, 2015 @02:31PM
(#10341202)
I was thinking the same thing - Extention Methods on the types of common literals can make for some very pretty interfaces.
In combination with operator overloads and implicit casts and you have some really powerful tools for building readable APIs :)
It's a real library I wrote. I just noticed I missed the brackets. Quick example you can infer the rest from:
Code:
public static class IntegerExtensions
{
public static TimeSpan Minutes(this int val)
{
return TimeSpan.FromMinutes(val);
}
}
Usage examples I can think of: var eightMinutes = 8.Minutes();
var tenMinutes = 8.Minutes() + 2.Minutes();
DoSomethingEvery(8.Minutes());Yeah I figured. Is it published/OSS?
Not at the moment. I've got a ton of stuff I probably could publish however.
Just a note, because I started in the same way you have, simply writing my own extension methods in a common dll. The Humanizer library has a bunch of these features, including the 6.minutes() functionality:
By themselves, the overloads for integers like that is pretty neat, never seen that before. I can actually think of several dozen places I do things like TimeSpan.FromSeconds(x) where that could enhance readability.