如何在C#中找到Properties.Resources的所有成员

时间:2009-08-21 08:54:59

标签: c# resources properties

我在C#程序集中有一些资源,我通过

解决
byte[] foob = Properties.Resources.foo;
byte[] barb = Properties.Resources.bar;
...

我想迭代这些资源,而不必保留我添加的索引。是否有返回所有资源的方法?

3 个答案:

答案 0 :(得分: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”和“Culture”属性。

答案 1 :(得分:2)

试试Assembly.GetManifestResourceNames()。这样称呼:

Assembly.GetExecutingAssembly().GetManifestResourceNames()

修改:要实际获取资源调用Assembly.GetManifestResouceStream()或查看更多详细信息,请使用Assembly.GetManifestResourceInfo()

答案 2 :(得分:0)

CampingProfile是资源文件

var resources =  CampingProfile.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry resource in resources)
{
    ;
}

这为您提供了资源文件中的所有属性,而没有其他属性