Search code examples
c#resourcesresx

C# customized resx with localization


In C# resources can be retrieved with a given file name like

ResourceManager rm = new ResourceManager("namespace.myresource",this.GetType().Assembly);
string someString = rm.GetString("GeneralError", culture);

With this, localization can be achieved by having the culture to the end of file. But I need to have it to customize to instance level also.

ex: myresource.instance1.resx, myresource.instance3.resx, myresource.instance1.fr-FR.resx,..etc.

But with the basic resourcemanager, this cannot be achieved. Is there any specific way to read the resources like this? (db approach is not suitable for the application)


Solution

  • @Nino - Thanks for the help.

    This can be sorted out as below

    var rsxr = new ResXResourceReader("MyResource.resx");
    rsxr.UseResXDataNodes = true;
    foreach (DictionaryEntry dEntry in rsxr)
    {
        var node = (ResXDataNode)dEntry.Value;
        if (node.FileRef == null)
        {
            var paramValue = node.GetValue((ITypeResolutionService) null);
        }
    }