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

I have some resources in C # assembly that I am addressing

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

I would like to iterate over these resources without having to keep an index of what I added. Is there a method that returns all resources?

+4
source share
3 answers

EDIT: Turns out these are properties, not 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.

+5
source

Give it a try Assembly.GetManifestResourceNames(). Call it that:

Assembly.GetExecutingAssembly().GetManifestResourceNames()

Edit: to receive a call to a resource Assembly.GetManifestResouceStream()or to view more details, use Assembly.GetManifestResourceInfo().

+2
source

CampingProfile -

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

0

Source: https://habr.com/ru/post/1715694/


All Articles