如何从namespace.class名称中找到文件路径? [英] How do I find the file path from a namespace.class name?
问题描述
我以编程方式查看 .aspx 文件,并获取在其CodeBehind中声明的文件类名称.例如,当分析 myFile.aspx 时,我读了它的Page Directive,发现其CodeBehind等于" myApplication \ myPage.aspx.vb ".然后我使用下面的代码:
I''m programatically looking into an .aspx file and getting the file class name declared in its CodeBehind. For example, when analyzing myFile.aspx, I read in its Page Directive and found its CodeBehind equals "myApplication\myPage.aspx.vb". Then I use the code below:
Dim Assm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("myApplication\bin\myApplication.dll")
Dim ClassType As Type = Assm.GetType("myApplication\myPage.aspx.vb")
'' myBaseType = "myApplication.Forms.BasePage"
Dim myBaseType As System.Type = ClassType.BaseType
现在,我想阅读BaseFile (class = myApplication.Forms.BasePage)
.但是,要读取此文件,我需要获取其完整路径而不是其namespace.class
层次结构.在这种情况下,BasePage
被包装在不同的名称空间声明中,因此我不能仅将''.''更改为\\以获取路径.
如何获取BasePage
的路径,以便可以阅读?谢谢-弗兰克
Now I want to read the BaseFile (class = myApplication.Forms.BasePage)
. However, to read in this file, I need to get its full path instead of its namespace.class
hierarchy. In this case, the BasePage
is wrapped in a different namespace declaration, thus I cannot just change the ''.'' to ''\'' in order to get the path.
How can I get the path of BasePage
so I can read it? Thank you - Frank
推荐答案
尝试一下(不保证,但是可能会为您提供一个起点):
Try this (no guarantees, but it might give you a place to start):
String strPath = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetAssembly(ClassType.BaseType));
感谢John,
不幸的是,GetDirectoryName()需要一个字符串...但是GetAssembly()返回一个类型.
Thanx John,
Unfortunately, GetDirectoryName() expects a string...but GetAssembly() returns a type.
这篇关于如何从namespace.class名称中找到文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!