Jak uzyskać dynamicznie zlokalizowany tekst w Windows Phone 8? dowiem się, że jeśli chcę tekst mogę to zrobić przez:Uzyskiwanie dynamicznych lokalizacji ciągów znaków WP8 C#
AppResources.ERR_VERSION_NOT_SUPPORTED
Ale załóżmy, że mam moje słowa kluczowego z serwera. Wracam tylko ciąg
ERR_VERSION_NOT_SUPPORTED
Teraz chciałbym uzyskać prawidłowy tekst z AppResources
.
Próbowałem następujące:
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 jest w tym przykładzie MethodInfo
mi jest null ...
ktoś ma jakieś pomysły?
EDIT:
Dziękuję wszystkim za szybkie odpowiedzi. w rzeczywistości Jestem całkiem nowy z C# i zawsze mieszam Properties
z powodu składni getters i setters.
mój AppResources
wygląda następująco:
/// <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);
}
}
}
próbują również uzyskać własność skończyło się dynamicznie nie działa ... i zorientowali się, można korzystać bezpośrednio w ten sposób:
string message = AppResources.ResourceManager.GetString("ERR_VERSION_NOT_SUPPORTED", AppResources.Culture);
Cheers do wszystkich
Czy jesteś pewien, że 'ERR_VERSION_NOT_SUPPORTED' jest metodą? – polkduran