2011-02-17 64 views
1

我按照从以下链接指引创建一个自定义的资源提供者:我使用下面的代码 http://asp-net-whidbey.blogspot.com/2006/03/aspnet-20-custom-resource-provider.htmlC# - 如何从自定义资源提供程序读取字符串值?

在.aspx页,它很好地工作:

<asp:Literal ID="ltlFoo" runat="server" Text="<%$ Resources:SomeText %>" /> 

现在,我想从代码中读取本地化值:

string foo = Resources.GetString("SomeText"); 

问题是我不知道如何实例化资源管理器。
任何帮助将不胜感激!

编辑:
我用下面的代码,它的伟大工程:

string foo = (string)GetGlobalResourceObject("", "SomeText"); 

是否有任何理由为什么我不应该使用这个代码吗?

回答

1

所以你的资源经理应该有一个名字,你应该可以做类似于以下的事情。

// 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"); 

Taken From MSDN Example

+0

如何获取资源管理器的名称? – 2011-02-17 16:55:31

相关问题