如何将 DTE.ActiveWindow.Selection 转换为 VS2008 宏中最接近的 CodeElement?
我正在使用 Visual Studio 2008 对象模型,如下所示: VS2008自动化对象模型图表。
我想对 VS2008 Marco 中的 CodeElement
进行操作,该 Marco 由用户在当前 .cs 文档中的文本选择来选择。
虽然我并不关心如何获得它,但这就是我尝试过的:VS 对象模型为您提供了 DTE.ActiveWindow.Selection
,其类型为 TextSelection
,并且然后是 DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint()
方法,该方法采用 TextPoint
和 vsCMEElement
作为参数并返回 CodeElment
就像我想要的那样。
但是我似乎无法从 TextSelection
中获取 TextElement
。
有人可以告诉我如何从 .cs 文件中的选定文本中获取 CodeElement
吗?
I'm working with the Visual Studio 2008 object model as seen here: VS2008 Automation Object Model Chart.
I want to act on a CodeElement
in a VS2008 Marco, one that is chosen by the user's text selection in the current .cs document.
While I don't really care how I get it, this is what I tried: The VS object model gives you DTE.ActiveWindow.Selection
which is of type TextSelection
, and then there is the DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint()
method which takes a TextPoint
and vsCMEElement
as parameters and returns the CodeElment
like I want.
However I can't seem to get a TextElement
from a TextSelection
.
Can someone tell me how to get a CodeElement
from the selected text in a .cs file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
textSelection = DTE.ActiveWindow.Selection
codeElement = textSelection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass)
Try this:
textSelection = DTE.ActiveWindow.Selection
codeElement = textSelection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass)