简体   繁体   中英

namespace of page which called this method

this code gives me Extentions namespace but I need aspx page namespace, how do I reach that? or I can use basepage for this method if better.

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 >

<%=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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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