以编程方式读取资源字符串 [英] Read Resource strings programmatically
问题描述
我大约说6个dll(没有源代码).它们不包含任何逻辑,而仅包含包含字符串表的.resx文件.
I Have around say 6 dll's ( No source code ). They do not contain any Logic but just a .resx file that contains a string table.
有没有一种方法可以从每个dll的字符串表中提取ID和值并将其导出到文本文件?
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");
要列出所有键和值,可以使用 ResourceSet
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.
这篇关于以编程方式读取资源字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!