Get dynamic row dynamics of WP8 C #

How can I get localized text dynamically in a Windows 8 phone? I find out that if I want text, I can do this:

AppResources.ERR_VERSION_NOT_SUPPORTED 

But suppose I get my keyword from the server. I am returning a string

 ERR_VERSION_NOT_SUPPORTED 

Now I would like to get the correct text from AppResources .

I tried the following:

 string methodName = "ERR_VERSION_NOT_SUPPORTED"; AppResources res = new AppResources(); //Get the method information using the method info class MethodInfo mi = res.GetType().GetMethod(methodName); //Invoke the method // (null- no parameter for the method call // or you can pass the array of parameters...) string message = (string)mi.Invoke(res, null); 

problem in this example: MethodInfo mi null ...

Does anyone have any idea?

EDIT:

Thanks to everyone for the quick answers. I'm actually quite new to C #, and I always mix Properties due to the syntax of getters and seters.

my AppResources looks like this:

 /// <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()] public class AppResources { ... /// <summary> /// Looks up a localized string similar to This version is not supported anymore. Please update to the new version.. /// </summary> public static string ERR_VERSION_NOT_SUPPORTED { get { return ResourceManager.GetString("ERR_VERSION_NOT_SUPPORTED", resourceCulture); } } } 

also trying to get a dynamic property that doesn't work ... and I realized that I could use this method directly:

 string message = AppResources.ResourceManager.GetString("ERR_VERSION_NOT_SUPPORTED", AppResources.Culture); 

Greetings to all

+7
source share
2 answers

You can access resources without using reflection. Try the following:

 AppResources.ResourceManager.GetString("ERR_VERSION_NOT_SUPPORTED", AppResources.Culture); 
+15
source

First of all, AppResources.ERR_VERSION_NOT_SUPPORTED not a method. This is a static property o static field. Therefore, you need to β€œsearch” for static properties (or fields). The following is an example of the properties:

 string name= "ERR_VERSION_NOT_SUPPORTED"; var prop = typeof(Program).GetProperty(name, BindingFlags.Static); string message = p.GetValue(null, null); 
0
source

All Articles