4 ms·
Aside, for both the circuit breaker and numeric overloads, is that a particular library you're using or just example code? By themselves, the overloads for int
by gregmac 11y ago
Aside, for both the circuit breaker and numeric overloads, is that a particular library you're using or just example code?
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.
- togusa 11y agoIt'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());
- gregmac 11y agoYeah I figured. Is it published/OSS?
- togusa 11y agoNot at the moment. I've got a ton of stuff I probably could publish however.
- jmcqk6 11y agoJust 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: https://github.com/MehdiK/Humanizer https://github.com/MehdiK/Humanizer
- radicalbyte 11y agoI 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 :)