Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-从基类获取页面的BaseType.名称和命名空间_C#_Class_Base - Fatal编程技术网

C#-从基类获取页面的BaseType.名称和命名空间

C#-从基类获取页面的BaseType.名称和命名空间,c#,class,base,C#,Class,Base,我的所有页面都有一个基类: //BASE CLASS public class WebBasePage : Page { protected override void OnLoad(EventArgs e) { base.OnLoad(e); string pageBaseTypeName = ???? string pageBaseTypeNameMespace = ???? } } //PAGE publi

我的所有页面都有一个基类:

//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.
    }
}
我希望这个基类的OnLoad事件动态地获取调用基类的页面的BaseType.Name和名称空间


有可能吗?

我假设您想要获取派生类名和命名空间,而不是基页名和命名空间(因为这永远不会改变)。只需调用
GetType
即可获得此信息:

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

GetType
调用将获取运行类型的信息

我假设您想要获取派生类名和命名空间,而不是基页名和命名空间(因为这永远不会改变)。只需调用
GetType
即可获得此信息:

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

GetType
调用将获取运行类型的信息

你需要一个“名称”还是需要根据类的类型来区分(例如,做某事)-有很多方法,取决于你需要它的原因我需要调用基类的页面的名称,在本例中为“T350112A”。你需要一个“名称”还是需要区分(例如,做某事)根据类的类型-有很多方法,取决于您需要它的原因。我需要调用基类的页面名称,在本例中为“T350112A”。在基类中,我希望以数字方式获取:pageBaseTypeName=“T350112A”。在基类中,我希望以数字方式获取:pageBaseTypeName=“T350112A”