2011-01-11 102 views
2

使用Visual Studio 2010如何以編程方式枚舉resx文件中的資源?

如何枚舉位於我的程序集內部的特定資源文件(.resx)中的所有資源?

在我的項目中,我有一個帶有3個文本文件(字符串資源)的Resources.resx文件。我需要列舉這3個文件,然後用他們的名字來獲取他們的內容。

謝謝。

回答

3

看出:

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 
5

使用ResXResourceReaderSystem.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(); 

}

+0

嗨@Andrzej,但如何我可以這樣做,如果resx文件在我的程序集內(在Visual Studio項目屬性窗口中生成)? – RHaguiuda 2011-01-11 11:12:17

相關問題