1
votes

I have an application that requires mappings between string values, so essentially a container that can hold key values pairs. Instead of using a dictionary or a name-value collection I used a resource file that I access programmatically in my code. I understand resource files are used in localization scenarios for multi-language implementations and the likes. However I like their strongly typed nature which ensures that if the value is changed the application does not compile.

However I would like to know if there are any important cons of using a *.resx file for simple key-value pair storage instead of using a more traditional programmatic type.

1

1 Answers

0
votes

There are two cons which I can think of out of the blue:

  • it requires I/O operation to read key/value pair, which may result in significant performance decrease,
  • if you let standard .Net logic to resolve loading resources, it will always try to find the file corresponding to CultureInfo.CurrentUICulture property; this could be problematic if you decide that you actually want to have multiple resx-es (i.e. one per language); this could result in even further performance degradation.

BTW. Couldn't you just create helper class or structure containing properties, like that:

public static class GlobalConstants
{
    private const int _SomeInt = 42;
    private const string _SomeString = "Ultimate answer";

    public static int SomeInt
    {
        get
        {
            return _SomeInt;
        }
    }

    public static string SomeString
    {
        get
        {
            return _SomeString;
        }
    }
}

You can then access these properties exactly the same way, as resource files (I am assuming that you're used to this style):

textBox1.Text = GlobalConstants.SomeString;
textBox1.Top = GlobalConstants.SomeInt;

Maybe it is not the best thing to do, but I firmly believe this is still better than using resource file for that...