我以编程方式查找.aspx文件并获取在其CodeBehind中声明的文件类名称。例如,在分析myFile.aspx时,我读了它的Page Directive,发现它的CodeBehind等于“myApplication \ myPage.aspx.vb”。然后我使用下面的代码:
[Code]
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
[/Code]
现在我想阅读BaseFile(class = myApplication.Forms.BasePage)。但是,要读入此文件,我需要获取其完整路径而不是其命名空间/类层次结构。在这种情况下,BasePage包含在不同的名称空间声明中,因此我不能只改变'。'到'\'。
如何获取BasePage的路径以便我可以阅读它?谢谢 - 弗兰克
答案 0 :(得分:0)
我认为您需要专注于通过GetType()方法获取类的
Dim SampleAssembly As [Assembly]
' Instantiate a target object.
Dim myType As New Customer()
Dim Type1 As Type
' Set the Type instance to the target class type.
Type1 = myType.GetType()
' Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = [Assembly].GetAssembly(myType.GetType())
' Gets the location of the assembly using file: protocol.
Console.WriteLine(("CodeBase=" + SampleAssembly.CodeBase))
您可以通过以下链接阅读更多内容:
Assembly.CodeBase属性:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.codebase.aspx