Sometimes you want to set a specific CultureInfo, do something and afterwards reset to the original CultureInfo. We wanted to do that when rendering a pdf, which had to work with dates in the correct format.
So what we did was this:
var originalCultureInfo = Thread.CurrentThread.CurrentCulture;
var culture = new CultureInfo("fr-FR");
Thread.CurrentThread.CurrentCulture = culture;
RenderPdf();
Thread.CurrentThread.CurrentCulture = originalCultureInfo;
But that can be made a lot simpler, with less risk of forgetting to reset the CurrentCulture on the last line:
using (new CustomCulture("fr-FR"))
{
RenderPdf();
}
The key is writing a CustomCulture class that inherits from IDisposable:
public class CustomCulture : IDisposable
{
readonly CultureInfo _originalCultureInfo;
public CustomCulture(string name)
{
_originalCultureInfo = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo(name);
}
public void Dispose()
{
Thread.CurrentThread.CurrentCulture = _originalCultureInfo;
}
}
vrijdag 21 augustus 2015
donderdag 7 mei 2015
Bookmarks
Best practices
- Order of items in classes: Fields, Properties, Constructors, Methods http://stackoverflow.com/a/310967/369117
- Guidelines for Collections https://msdn.microsoft.com/en-us/library/dn169389
maandag 20 april 2015
Technical stories on the backlog
How can you add technical stories to the backlog when the product owner wants every story to have business value? Let's take the following titles as an example:
Connect the monitoring system to ServiceX.
Use the configuration system and not the web.config for settings of ServiceX.
As a developer these titles are perfectly fine. As a product owner the titles are too technical. One solution is to rewrite the titles in the following way:
As operations staff I want to monitor aspect A of ServiceX.
As operations staff I want to configure ServiceX with the configuration system.
Abonneren op:
Posts (Atom)