我有一些资源在一个C#程序集中,我通过以下方式进行访问:
byte[] foob = Properties.Resources.foo;
byte[] barb = Properties.Resources.bar;
...
我希望能够遍历这些资源,而不必保留已添加的索引。是否有一种方法可以返回所有资源?
我有一些资源在一个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));
}
Assembly.GetManifestResourceNames()
。像这样调用它:Assembly.GetExecutingAssembly().GetManifestResourceNames()
编辑:要获取资源,请调用Assembly.GetManifestResouceStream()
,或者查看更多详细信息,请使用Assembly.GetManifestResourceInfo()
。
CampingProfile
是资源文件。
var resources = CampingProfile.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry resource in resources)
{
;
}
这将为您提供资源文件中的所有属性,而不包括其他属性