繁体   English   中英

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

[英]How can I find all the members of a Properties.Resources in C#

我在C#程序集中有一些资源,我在其中解决

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

我想迭代这些资源,而不必保留我添加的索引。 有没有一种方法可以返回所有资源?

编辑:事实证明他们是属性而不是字段,所以:

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”属性。

尝试Assembly.GetManifestResourceNames() 像这样称呼它:

Assembly.GetExecutingAssembly().GetManifestResourceNames()

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

CampingProfile是资源文件

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

这将为您提供资源文件中的所有属性,而不包含其他属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM