这是我的代码:
var assem = Assembly.GetExecutingAssembly();
var fs = assem.GetManifestResourceStream("res.resources");
var rr = new ResourceReader(fs);`
IDictionaryEnumerator dict = rr.GetEnumerator();
感谢您的帮助
答案 0 :(得分:2)
您可以使用LINQ将ResourceReader
提供的数据转换为可能更容易使用的字典:
using System.Linq;
using System.Collections.Generic;
var assem = Assembly.GetExecutingAssembly();
var fs = assem.GetManifestResourceStream("res.resources");
var rr = new ResourceReader(fs);
Dictionary<string, object> data = rr
.OfType<DictionaryEntry>()
.Select(i => new { Key = i.Key.ToString(), value = i.Value })
.ToDictionary(i => i.Key, i => i.value);
// Getting all resource names
IEnumerable<string> names = data.Keys;
// Getting all values
IEnumerable<object> values = data.Values;
答案 1 :(得分:1)
var assem = Assembly.GetExecutingAssembly();
var fs = assem.GetManifestResourceStream("res.resources");
var rr = new ResourceReader(fs);`
IDictionaryEnumerator dict = rr.GetEnumerator();
while (dict.MoveNext())
Console.WriteLine(" {0}: '{1}' (Type {2})",
dict.Key, dict.Value, dict.Value.GetType().Name);
rr.Close();
答案 2 :(得分:0)
如果需要程序集中所有资源的列表,请使用以下
var assem = Assembly.GetExecutingAssembly();
var resources = assem.GetManifestResourceNames();