Search code examples
c#.netdlldictionaryresx

How to turn a resx resource file into a dictionary


I'm currently working on a dll which would be used across future projects, and trying to fill it with every useful method developped in the last one. One of these methods that i'd like to re-use allows to generate an excel file with any object collection, and uses a resx resource file to get the column headers based on the object's property names.

Now, my problem is that I can't access or even check the existence of such a file from the library. A possible workaround would be to turn this resource file into a dictionary and pass it as a parameter, but I didn't find a way to do so or any documentation on the subject. Any hint or suggestion about this ?

Thank you for helping me here...

P.S. : I'm working with Visual Studio 2013, in case that could be relevant.


Solution

  • Here's a workaround I found and which allows to get a "RuntimeResourceSet" object, which is structurally close to a dictionnary (and which could be easily turned into one, if you specifically need a dictionnary) :

    var myResourceSet = MyResource.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
    

    Then, you can get the set's items this way :

    var myString = myResourceSet.GetString("MyKey");
    

    Hope that will help !