[英]namespace of page which called this method
這段代碼為我提供了Extensions命名空間,但是我需要aspx頁面命名空間,如何實現? 或者,如果更好,我可以使用basepage來實現此方法。
班級圖書館>
public static class Extentions
{
public static string LANG(string text)
{
Type type = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
string ns = type.Namespace.Replace(".", "_");
return (string)HttpContext.GetGlobalResourceObject("language", ns + "_" + text);
}
}
在某些ASPX頁面中>
<%=Extentions.LANG("Header")%>
這適用於我的具體問題;
public string LANG(string text)
{
string ns = this.GetType().BaseType.FullName.Replace(".", "_");
return (string)HttpContext.GetGlobalResourceObject("language", ns + "_" + text);
}
像這樣在您的頁面中包含一個公共財產:
public string PageNamespace
{
get { return this.GetType().Namespace; }
}
在頁面中顯示此屬性:
<%= PageNamespace %>
注意:您可以使用以下代碼: this.GetType().Namespace
來獲取任何非靜態頁面方法內部的頁面名稱空間。 我在最初的答案中給出了此解決方案,但該方法不適用於OP,因為他試圖以靜態方法訪問它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.