views:

304

answers:

1

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?

Thanks!

A: 

Try this:

textSelection = DTE.ActiveWindow.Selection

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

Bob Dizzle