2009-08-21 34 views

回答

5

編輯:原來,他們的屬性而不是字段,因此:

foreach (PropertyInfo property in typeof(Properties.Resources).GetProperties 
    (BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) 
{ 
    Console.WriteLine("{0}: {1}", property.Name, property.GetValue(null, null)); 
} 

注意,這也將讓您的「ResourceManager的」和「文化」的特性。

+0

是不是比通過GetManifestResource *直接訪問資源慢呢? – 2009-08-21 09:14:05

+0

他們做不同的事情。一方面,你可能在程序集中有不在'Properties.Resources'中的內容,其次它會給你單獨的資源而不是資源*文件*。例如,如果您有兩個字符串資源,則它們可能都在同一個資源文件中 - 查找資源名稱意味着加載文件,然後詢問該文件中的名稱等。 – 2009-08-21 09:27:37

+0

換句話說,此答案可以解決問題特意要求:) – 2009-08-21 09:28:30

2

嘗試Assembly.GetManifestResourceNames()。這樣稱呼它:

Assembly.GetExecutingAssembly().GetManifestResourceNames() 

編輯:實際得到的資源調用Assembly.GetManifestResouceStream()或查看更多詳細信息使用Assembly.GetManifestResourceInfo()