简体   繁体   中英

C# - get BaseType.Name and Namespace of the Page from base class

I've a base class for my all pages:

//BASE CLASS
public class WebBasePage : Page
{
    protected override void OnLoad(EventArgs e)
    {
          base.OnLoad(e);
          string pageBaseTypeName = ????
          string pageBaseTypeNameMespace = ????
    }
}
//PAGE
public partial class T350112A : WebBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Some code.
    }
}

I want the OnLoad event of this base class to dynamically get the BaseType.Name and the Namespace of the Page that called the base class.

Is It possible?

I'm assuming you want to get the derived class name and namespace, instead of the base page name and namespace (since that will never change). You would simply get a call to GetType to get this information:

  public override void OnLoad(EventArgs e)
  {
       Type derivedType = GetType();
       string typeName = derivedType.Name;
       string namespace = derivedType.Namespace;
  }

The GetType call will get the information for the running type.

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