简体   繁体   English

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

[英]namespace of page which called this method

this code gives me Extentions namespace but I need aspx page namespace, how do I reach that? 这段代码为我提供了Extensions命名空间,但是我需要aspx页面命名空间,如何实现? or I can use basepage for this method if better. 或者,如果更好,我可以使用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);
    }
}

IN SOME ASPX PAGE > 在某些ASPX页面中>

<%=Extentions.LANG("Header")%>

This works for my specific problem ; 这适用于我的具体问题;

public string LANG(string text) 
{ 
    string ns = this.GetType().BaseType.FullName.Replace(".", "_"); 
    return (string)HttpContext.GetGlobalResourceObject("language", ns + "_" + text); 
}

Include a public property in your page like this: 像这样在您的页面中包含一个公共财产:

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

Show this property in your page: 在页面中显示此属性:

<%= PageNamespace %>

NOTE: you can use this code: this.GetType().Namespace to get the page namespace inside of any page method which is not static. 注意:您可以使用以下代码: this.GetType().Namespace来获取任何非静态页面方法内部的页面名称空间。 I gave this solution in my original answer, but it didn't work for the OP because he was trying to access it in an static method. 我在最初的答案中给出了此解决方案,但该方法不适用于OP,因为他试图以静态方法访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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