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”