vrijdag 21 augustus 2015

Set and reset CultureInfo inside a using block

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;
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"))

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;

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.