繁体   English   中英

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM