Reading resource strings programmatically

I have about 6 dll (no source code). They do not contain any logic, but only a .resx file containing a string.

Is there a way in which I can extract the Id and values ​​from the row table from each of these dlls and export it to a text file?

+3
source share
2 answers

Knowing the assembly name and resource file, you can load it using reflection.

// Resources dll
var assembly = Assembly.LoadFrom("ResourcesLib.DLL");

// Resource file.. namespace.ClassName
var rm = new ResourceManager("ResourcesLib.Messages", assembly);

// Now you can get the values
var x = rm.GetString("Hi");

To list all keys and values, you can use ResourceSet

var assembly = Assembly.LoadFrom("ResourcesLib.DLL");
var rm = new ResourceManager("ResourcesLib.Messages", assembly);

var rs = rm.GetResourceSet(CultureInfo.CurrentCulture, true, true);

foreach (DictionaryEntry r in rs)
{
    var key = r.Key.ToString();
    var val = r.Value.ToString();
}

If you don't have access to lib resources, you can see what namespaces, classes and everything else are through Reflector as mentioned by Leo.

+6
source
+1

Source: https://habr.com/ru/post/1767294/


All Articles