我的所有页面都有一个基类:
//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事件能够动态获取调用该基类的Page的BaseType.Name和Namespace。
这可能吗?
最佳答案
我假设您想要获取派生类名称和命名空间,而不是基本页面名称和命名空间(因为它永远不会改变)。您只需调用 GetType
即可获取此信息:
public override void OnLoad(EventArgs e)
{
Type derivedType = GetType();
string typeName = derivedType.Name;
string namespace = derivedType.Namespace;
}
GetType
调用将获取正在运行类型的信息。
关于C# - 从基类获取页面的 BaseType.Name 和命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10212185/