调用此方法的页面的命名空间

时间:2014-07-14 11:49:13

标签: c# asp.net

这段代码给了我Extentions命名空间但是我需要aspx页面命名空间,我该如何实现?或者如果更好的话,我可以使用basepage作为这种方法。

CLASS LIBRARY>

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); 
}

1 个答案:

答案 0 :(得分:1)

在您的网页中加入公共财产,如下所示:

public string PageNamespace
{
    get { return this.GetType().Namespace; }
}

在您的信息页中显示此媒体资源:

<%= PageNamespace %>

注意:您可以使用此代码:this.GetType().Namespace来获取任何非静态页面方法内的页面命名空间。我在原始答案中给出了这个解决方案,但它对OP没有用,因为他试图用静态方法访问它。