2

这是我的代码:

var assem = Assembly.GetExecutingAssembly();
var fs = assem.GetManifestResourceStream("res.resources");
var rr = new ResourceReader(fs);`
IDictionaryEnumerator dict = rr.GetEnumerator();

谢谢你的帮助

4

3 回答 3

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;
于 2012-06-29T07:20:25.040 回答
1

改编自MSDN 文档

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();
于 2012-06-29T07:04:49.527 回答
0

如果您想要程序集中所有资源的列表,请使用以下内容

var assem = Assembly.GetExecutingAssembly(); 
var resources = assem.GetManifestResourceNames();
于 2012-06-29T07:02:43.643 回答