[英]C# - How to read string value from the custom resource provider?
I created a custom resource provider by following guidelines from the following link: http://asp-net-whidbey.blogspot.com/2006/03/aspnet-20-custom-resource-provider.html 我通过以下链接中的准则创建了一个自定义资源提供程序: http : //asp-net-whidbey.blogspot.com/2006/03/aspnet-20-custom-resource-provider.html
On .aspx pages I'm using the following code and it work fine: 在.aspx页面上,我正在使用以下代码,它工作正常:
<asp:Literal ID="ltlFoo" runat="server" Text="<%$ Resources:SomeText %>" />
Now I'd like to read the localized value from the code: 现在,我想从代码中读取本地化的值:
string foo = Resources.GetString("SomeText");
The problem is that I don't know how to instantiate the resource manager. 问题是我不知道如何实例化资源管理器。
Any help would be greatly appreciated! 任何帮助将不胜感激!
EDIT: 编辑:
I used the following code and it works great: 我使用了以下代码,效果很好:
string foo = (string)GetGlobalResourceObject("", "SomeText");
Is there any reason why I should not use that code? 有什么原因使我不应该使用该代码?
So your resource manager should have a name and you should be able to do something similar to the following. 因此,您的资源管理器应该有一个名称,并且您应该能够执行以下操作。
// 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.