访问 VS 扩展中的 XAML 内容



我目前正在开发一个扩展,可以帮助我扫描代码,尤其是 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

我开始意识到那个文件。Open(EnvDTE.Constants.vsViewKindCode(给了我关联的xaml.vb代码,而不是xaml代码本身。但是当我尝试使用文件时。Open(EnvDTE.Constants.vsViewKindDesigner(,获胜。ProjectItem.FileCodeModel 什么都不是。

任何帮助表示赞赏。谢谢。:)

得到了答案:

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)

最新更新