使用Visual Studio 2010
如何枚举位于程序集内的特定资源文件(.resx)中的所有资源?
在我的项目中,我有一个包含3个文本文件的Resources.resx文件(字符串资源).我需要枚举这3个文件,然后使用它们的名称来获取它们的内容.
谢谢.
使用ResXResourceReader从System.Windows.Forms.
它枚举XML资源(.resx)文件和流,并读取顺序资源名称和值对
public static void Main()
{
// Create a ResXResourceReader for the file items.resx.
ResXResourceReader rsxr = new ResXResourceReader("items.resx");
// Iterate through the resources and display the contents to the console.
foreach (DictionaryEntry d in rsxr)
{
Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString());
}
//Close the reader.
rsxr.Close();
Run Code Online (Sandbox Code Playgroud)
}
发现:
Dim man As New ResourceManager("Discovery.Resources", Assembly.GetExecutingAssembly)
Dim resset As ResourceSet
resset = man.GetResourceSet(CultureInfo.CurrentCulture, True, True)
For Each item As DictionaryEntry In resset
Console.WriteLine(item.Key)
Next
Run Code Online (Sandbox Code Playgroud)