本文介绍了asp.net,将gettype()和完全限定类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过这里了一些其他线程读取,虽然他们没有真正解释如何解决我的问题。

I've read through a few other threads on here, though none of them really explain how to resolve my issue.

我有以下页面(code后面)

I have a web application with the following page (code behind)

namespace Company.Web.UI.Content
{
  public partial class Home_LoggedOut : Company.Web.UI.CompanyPage
  {
    string _myType = this.GetType().FullName.Replace(".", "_");
  }
}

现在我会希望得到的是这样的:

Now I'd have hoped to get something like:

Company_Web_UI_Content_Home_LoggedOut

而是我得到:

ASP_home_loggedout_aspx

我清楚地失去了一些东西有关类的结构以及它们如何工作,所以我想明白,但有什么办法,我让在这种情况下完全合格的命名空间+类名?

I'm clearly missing something about class structures and how they work, so I'd like to understand that, but is there any way for me to get the fully qualified namespace + class name in this scenario?

在理想情况下,我想这包括在基本类型(Company.Web.UI.CompanyPage),这样我可以用它做什么,使建议什么就必须在这一水平太多的工作。

Ideally, I'd like to include this in the base type (Company.Web.UI.CompanyPage) so that I can do something with it, so anything that is suggested would have to work at that level too.

希望我没有在这里完全错过了点(当然,我可能是,但我希望有办法解决它!)

Hope I'm not completely missing the point here (well, I probably am, but hopefully there is a way around it!)

干杯,
特里

更新:
答进来为:

Update:Answer came in as:

string _myType = this.GetType().BaseType.FullName.Replace(".", "_");

感谢家伙:)

推荐答案

当你有一个code页面后面你确实有两班。一个是从code其背后得到由类的页面继承。这就是为什么你得到这个名字。试试这个,看看它是否工作:

When you have a page with a code behind you actually have two classes. One is from the code behind which gets inherited by the class for the page. That's why you get that name. Try this and see if it works:

string _myType = this.GetType().BaseType.FullName.Replace(".", "_");

这篇关于asp.net,将gettype()和完全限定类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:04