使用 Visual Studio 2010
如何枚举位于我的程序集中的特定资源文件 (.resx) 中的所有资源?
在我的项目中,我有一个包含 3 个文本文件(字符串资源)的 Resources.resx 文件。我需要枚举这 3 个文件,然后使用它们的名称来获取它们的内容。
谢谢。
最佳答案
使用 ResXResourceReader来自 System.Windows.Forms
.
It Enumerates XML resource (.resx) files and streams, and reads the sequential resource name and value pairs
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();
}
关于.net - 如何以编程方式枚举 resx 文件中的资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4656883/