0

I try to get all resource names from properties.resources and fill listbox with them. Here is code:

static string GetNameOf<T>(Expression<Func<T>> property)
{
    return (property.Body as MemberExpression).Member.Name;
}
private void button_Click(object sender, RoutedEventArgs e)
{
    var s = GetNameOf(() => Properties.Resources.Lil);
    MessageBox.Show(s);
}

(with this button and messagebox i try output)

Here is OK, but the problem is that i must take every resource separately. My idea is to take names foreach resource most inteligent. Maybe is easy but I still learn and I'm still new in codding.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • Possible duplicate of [Loop through all the resources in a .resx file](https://stackoverflow.com/questions/2041000/loop-through-all-the-resources-in-a-resx-file) – ASh Aug 14 '17 at 13:30

1 Answers1

1

Try this:

var properties = typeof(Properties.Resources).GetProperties(
    System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic |
    System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static);

foreach (var propertyInfo in properties)
{
    var s = propertyInfo.Name;
    if(s != "ResourceManager" && s != "Culture")
    {
        MessageBox.Show(s);
    }
}
mm8
  • 163,881
  • 10
  • 57
  • 88