Read Resource strings programmatically
I Have around say 6 dll's ( No source code ). They do not contain any Logic b开发者_开发问答ut just a .resx file that contains a string table.
Is there a way where I can extract the Id's and values from the string table from each of these dll's and Export it to a text file?
Knowing the assembly name and the 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 the 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 the resources lib, you can see what are the namespaces, classes, and everything else through Reflector as mentioned by Leo.
精彩评论