peter.murray.rust
peter.murray.rust

Reputation: 38043

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

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?

Upvotes: 4

Views: 4087

Answers (3)

draco951
draco951

Reputation: 368

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

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500903

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.

Upvotes: 5

J. Random Coder
J. Random Coder

Reputation: 1342

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().

Upvotes: 2

Related Questions