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

C# 在WP8 c中动态获取本地化字符串#,c#,windows-phone-8,C#,Windows Phone 8,如何在windows phone 8中动态获取本地化文本? 我发现,如果我想要文本,我可以重新编写: AppResources.ERR_VERSION_NOT_SUPPORTED 但我们假设我从服务器上获取关键字。我只拿回绳子 ERR_VERSION_NOT_SUPPORTED 现在我想从AppResources获取正确的文本 我尝试了以下方法: string methodName = "ERR_VERSION_NOT_SUPPORTED"; AppResources res = new A

如何在windows phone 8中动态获取本地化文本? 我发现,如果我想要文本,我可以重新编写:

AppResources.ERR_VERSION_NOT_SUPPORTED
但我们假设我从服务器上获取关键字。我只拿回绳子

ERR_VERSION_NOT_SUPPORTED
现在我想从
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);
在本例中,问题是
MethodInfo
mi为空

有人有什么想法吗

编辑:

谢谢大家的快速回复。 事实上,我对c语言非常陌生,而且我总是混淆
属性
,因为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);
        }
    }
}

为所有人干杯

首先
通知来源。错误版本不受支持
不是一种方法。它是静态字段的静态属性。因此,您需要“搜索”静态属性(或字段)。以下属性示例:

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

您可以访问资源而不必使用反射。试试这个:

AppResources.ResourceManager.GetString(“错误版本不受支持”,
评价资源(文化);

您确定
错误版本\u不受支持
是一种方法吗?感谢Garath的建议!我试过了,但也使用了var prop为null的方法。但无论如何,我终于找到了解决办法…是的,谢谢!我现在也知道了:)看我的编辑。。。非常感谢你!
string name= "ERR_VERSION_NOT_SUPPORTED";
var prop = typeof(Program).GetProperty(name, BindingFlags.Static);
string message = p.GetValue(null, null);