[英]C# - How to read string value from the custom resource provider?
我通过以下链接中的准则创建了一个自定义资源提供程序: http : //asp-net-whidbey.blogspot.com/2006/03/aspnet-20-custom-resource-provider.html
在.aspx页面上,我正在使用以下代码,它工作正常:
<asp:Literal ID="ltlFoo" runat="server" Text="<%$ Resources:SomeText %>" />
现在,我想从代码中读取本地化的值:
string foo = Resources.GetString("SomeText");
问题是我不知道如何实例化资源管理器。
任何帮助将不胜感激!
编辑:
我使用了以下代码,效果很好:
string foo = (string)GetGlobalResourceObject("", "SomeText");
有什么原因使我不应该使用该代码?
因此,您的资源管理器应该有一个名称,并且您应该能够执行以下操作。
// Create a resource manager to retrieve resources.
ResourceManager rm = new ResourceManager("items",
Assembly.GetExecutingAssembly());
// Retrieve the value of the string resource named "welcome".
// The resource manager will retrieve the value of the
// localized resource using the caller's current culture setting.
String foo = rm.GetString("SomeText");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.