0

So I'm trying to retrieve the list of properties generated from a Strings.resx resource. A Strings class is auto-generated from that, and I'm simply trying to get a list of those property names. Below is some example code of what doesn't work.

// Well this works, so I know there is a property there.
var clearly_a_property = Strings.home_cancel;

// Yet none of this works
var nothing = typeof(Strings).GetProperties(System.Reflection.BindingFlags.Public | 
    System.Reflection.BindingFlags.Static | 
    System.Reflection.BindingFlags.FlattenHierarchy);
nothing = typeof(Strings).GetProperties(System.Reflection.BindingFlags.Public | 
    System.Reflection.BindingFlags.Instance | 
    System.Reflection.BindingFlags.FlattenHierarchy);
nothing = typeof(Strings).GetProperties(System.Reflection.BindingFlags.Public | 
    System.Reflection.BindingFlags.Static);
nothing = typeof(Strings).GetProperties(System.Reflection.BindingFlags.Public);
nothing = typeof(Strings).GetProperties(System.Reflection.BindingFlags.FlattenHierarchy);
nothing = typeof(Strings).GetProperties(System.Reflection.BindingFlags.Static);
nothing = typeof(Strings).GetProperties(System.Reflection.BindingFlags.Instance);
nothing = typeof(Strings).GetProperties(System.Reflection.BindingFlags.DeclaredOnly);
nothing = typeof(Strings).GetProperties();

So what gives? The class that's trying to access Strings is in the same assembly, so I don't think that's the problem.

Here is a snippet from the auto-generated Strings class.

/// <summary>
///   A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Strings {

    //------------------
    // other stuff ...
    //------------------

    internal static string home_cancel {
        get {
            return ResourceManager.GetString("home_cancel", resourceCulture);
        }
    }

    //------------------
    // other stuff ...
    //------------------
}
Ultratrunks
  • 2,464
  • 5
  • 28
  • 48

1 Answers1

2

You're missing NonPublic flag. Of course you need Static flag as well, as the property is static.

var something = typeof(Strings).GetProperties(BindingFlags.NonPublic | BindingFlags.Static);
Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189