动态获取本地化字符串WP8 c#

sch*_*tom 7 c# windows-phone-8

如何在Windows Phone 8中动态获取本地化文本?我发现,如果我想要一个文本,我可以做到这一点:

AppResources.ERR_VERSION_NOT_SUPPORTED
Run Code Online (Sandbox Code Playgroud)

但我们假设我从服务器获取了我的关键字.我只收回字符串

ERR_VERSION_NOT_SUPPORTED
Run Code Online (Sandbox Code Playgroud)

现在我想从中获取正确的文字AppResources.

我尝试过以下方法:

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);
Run Code Online (Sandbox Code Playgroud)

问题是在这个例子中MethodInfomi是null ...

谁有想法?

编辑:

谢谢大家的快速回复.事实上我对c#很新,Properties因为getter和setter语法,我总是混淆.

AppResources看起来像这样:

/// <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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

也试图动态地获得属性最终不起作用...我发现我可以直接使用这种方式:

string message = AppResources.ResourceManager.GetString("ERR_VERSION_NOT_SUPPORTED", AppResources.Culture);
Run Code Online (Sandbox Code Playgroud)

为所有人喝彩

Ala*_*oud 15

您无需使用反射即可访问资源.试试这个:

AppResources.ResourceManager.GetString("ERR_VERSION_NOT_SUPPORTED", 
      AppResources.Culture);
Run Code Online (Sandbox Code Playgroud)