0

Imagine I have the following 2 resx files:

Resource.resx

 add     |  add
 delete  |  delete
 edit    |  edit

Resource.nl.resx

 add     |  toevoegen
 delete  |  verwijderen

As you can see, the "nl" resource does not contain all keys of the base Resource file. When I get the values as following, I do not get all values.

var culture = Thread.CurrentThread.CurrentUICulture;
var resource = new ResourceManager(resxFileName, resourcesAssembly);
return resource.GetResourceSet(culture, true, true)
                                .Cast<DictionaryEntry>()
                                .ToDictionary(entry => entry.Key.ToString(), entry => entry.Value.ToString()); 

If the culture is "nl" I only get the add and delete keys, but I want it to fallback to "Resources.resx" for the edit key. Like:

 add     |  toevoegen
 delete  |  verwijderen
 edit    |  edit

Is there a standard way to do this?

I could get all keys from the base resourcefile and then loop them in order to make sure I have all keys. But that seems very inefficient.

Edwin Stoteler
  • 1,218
  • 1
  • 10
  • 25
  • The point of using ResourceManager is to get automatic fallback. Use its GetString() method. – Hans Passant Jan 12 '16 at 10:49
  • @HansPassant GetString() gets a specific string and assumes that you know it's key. The whole point of my question is how can I get all strings from the resource files, without knowing beforehand what keys there are. – Edwin Stoteler Jan 12 '16 at 12:31

0 Answers0