[英]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.