如何将DTE.ActiveWindow.Selection转换为VS2008宏中最接近的CodeElement?

时间:2023-01-14 18:57:41

I'm working with the Visual Studio 2008 object model as seen here: VS2008 Automation Object Model Chart.

我正在使用Visual Studio 2008对象模型,如下所示:VS2008自动化对象模型图表。

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.

我想对VS2008中的CodeElement采取行动,这是由当前.cs文档中用户的文本选择选择的。

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.

虽然我并不在乎我是如何得到它的,但这就是我尝试过的:VS对象模型为您提供了类型为TextSelection的DTE.ActiveWindow.Selection,然后是DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint( )将TextPoint和vsCMEElement作为参数并按我想要的方式返回CodeElment的方法。

However I can't seem to get a TextElement from a TextSelection.

但是我似乎无法从TextSelection获取TextElement。

Can someone tell me how to get a CodeElement from the selected text in a .cs file?

有人能告诉我如何从.cs文件中的选定文本中获取CodeElement吗?

1 个解决方案

#1


Try this:

textSelection = DTE.ActiveWindow.Selection

textSelection = DTE.ActiveWindow.Selection

codeElement = textSelection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass)

codeElement = textSelection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass)

#1


Try this:

textSelection = DTE.ActiveWindow.Selection

textSelection = DTE.ActiveWindow.Selection

codeElement = textSelection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass)

codeElement = textSelection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass)