I have some resources in a C# Assembly which I address by
byte[] foob = Properties.Resources.foo;
byte[] barb = Properties.Resources.bar;
...
I would like to iterate through these resources without having to keep an index of what I have added. Is there a method that returns all the resources?
EDIT: It turns out they're properties rather than fields, so:
foreach (PropertyInfo property in typeof(Properties.Resources).GetProperties
(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
{
Console.WriteLine("{0}: {1}", property.Name, property.GetValue(null, null));
}
Note that this will also give you the "ResourceManager" and "Culture" properties.
Try Assembly.GetManifestResourceNames()
. Call it like this:
Assembly.GetExecutingAssembly().GetManifestResourceNames()
Edit: To actually get the resource call Assembly.GetManifestResouceStream()
or to view more details use Assembly.GetManifestResourceInfo()
.
CampingProfile
is the resource file
var resources = CampingProfile.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry resource in resources)
{
;
}
This give you all properties into the resource file without the others properties
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.