.net - 如何以编程方式枚举 resx 文件中的资源?

标签 .net resources

使用 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/

相关文章:

.net - 调整对象图的 XAML 序列化

c# - C#中旋转图片剪切图片

android - 为什么 setImageResource 什么都不显示?

java - Class.getResource() 的奇怪行为

当应用程序最小化到托盘时,C# MessageBox 显示在前面

.net - 从 .Net 调用 FoxPro 报告

.net - 如何调试.NET中的反序列化错误?

file - 编译后使用 CHEF 中的文件资源复制本地文件

c# - ASP.NET Web API 可以处理具有不同 Controller 的子资源吗

C# 使用资源中的 NAudio 播放 MP3 文件