2011-01-11 16 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から使用してください。

それは(の.resx) ファイルXMLリソースを列挙し、ストリーム、および シーケンシャルリソース名と値 ペアを発見

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ファイルがアセンブリ内にある場合(ビジュアルスタジオのプロジェクトプロパティウィンドウで生成されます)はできますか? – RHaguiuda

+0

@RHaguiudaここをクリックしてください:http://msdn.microsoft.com/en-us/library/aa984408%28VS.71%29.aspx – nan

関連する問題