我目前正在开发一个扩展程序,该扩展程序可以帮助我扫描代码,尤其是XAML文件。有关我的问题的代码如下:
For Each file As ProjectItem In SolutionFiles()
If file.Name.EndsWith(".xaml") Then
Dim win As Window = file.Open(EnvDTE.Constants.vsViewKindCode)
For Each elem As CodeElement In win.ProjectItem.FileCodeModel.CodeElements
Dim strLine() As String = elem.StartPoint.CreateEditPoint().GetText(elem.EndPoint).Split("vbcrlf")
Dim Linecount As Integer = 0
For Each line As String In strLine
...
Next
Next
End If
Next
我开始意识到file.Open(EnvDTE.Constants.vsViewKindCode)给了我相关的xaml.vb代码,而不是xaml代码本身。但是,当我尝试使用file.Open(EnvDTE.Constants.vsViewKindDesigner)时,win.ProjectItem.FileCodeModel无效。
任何帮助表示赞赏。谢谢。 :)
答案 0 :(得分:0)
得到答案:
Dim codeWin As Window = file.Open(EnvDTE.Constants.vsViewKindPrimary)
Dim fileName As String = If(codeWin IsNot Nothing, codeWin .Document.Path & file.Name, Nothing)
Dim content As String = If(Not String.IsNullOrEmpty(fileName), System.IO.File.ReadAllText(fileName), Nothing)