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

发布于 2024-07-13 09:08:39 字数 719 浏览 16 评论 0原文

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

我想对 VS2008 Marco 中的 CodeElement 进行操作,该 Marco 由用户在当前 .cs 文档中的文本选择来选择。

虽然我并不关心如何获得它,但这就是我尝试过的:VS 对象模型为您提供了 DTE.ActiveWindow.Selection ,其类型为 TextSelection,并且然后是 DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint() 方法,该方法采用 TextPointvsCMEElement 作为参数并返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叶落知秋 2024-07-20 09:08:39

试试这个:

textSelection = DTE.ActiveWindow.Selection

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

Try this:

textSelection = DTE.ActiveWindow.Selection

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文