Làm cách nào để có được văn bản được bản địa hóa động trong cửa sổ điện thoại 8? tôi tìm ra rằng nếu tôi muốn có một văn bản tôi có thể làm điều này trên:Nhận bản địa hóa chuỗi động WP8 C#
AppResources.ERR_VERSION_NOT_SUPPORTED
Nhưng chúng ta hãy giả sử tôi có được từ khoá của tôi từ máy chủ. Tôi chỉ lấy lại chuỗi
ERR_VERSION_NOT_SUPPORTED
Bây giờ tôi muốn nhận được văn bản thích hợp từ AppResources
.
Tôi đã thử những điều sau đây:
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);
vấn đề là trong ví dụ này MethodInfo
mi là null ...
ai có một số ý tưởng?
EDIT:
Cảm ơn tất cả các bạn đã phản ứng nhanh chóng. trong thực tế tôi khá mới với C# và tôi luôn luôn mixup các Properties
vì getters và setters cú pháp.
AppResources
của tôi trông như thế này:
/// <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);
}
}
}
cũng cố gắng để có được tài sản động đã kết thúc không làm việc ... và tôi đã tìm ra tôi có thể trực tiếp sử dụng theo cách này:
string message = AppResources.ResourceManager.GetString("ERR_VERSION_NOT_SUPPORTED", AppResources.Culture);
Cheers cho tất cả
Bạn có chắc chắn rằng 'ERR_VERSION_NOT_SUPPORTED' là một phương pháp không? – polkduran