views:

23

answers:

1

So I'm playing around with EnvDTE, and the EnvDTE.CodeModel API, And I was wondering if there was a way to get the text value represented by a CodeElement.

Let's say I have an CodeAttribute, is there some way to get a string of what the CodeAttribute represents, i.e.[MyAttribute(value="myvalue")].

I know it's possible to reconstruct the code using the various properties of the CodeElement, at least in some scenarios, but for some things it seems it would be easier to just get the text.

Thanks!

+2  A: 

The CodeElement interface has the properties StartPoint and EndPoint which represent the start and end of the element within the buffer. These contain the Line Number / Column which can be passed to methods like IVsTextLines.GetLineText and give you back the value you're looking for.

JaredPar
I guess my next question should be, how do I get a reference to an `IVsTextLines`? I am also wondering if this would require the file to be open in the editor, and thus in the text buffer. I am trying to implement something project/solution wide, using `Project.CodeModel` so I would be exploring the model without the file being open. This may not be possible though.
Master Morality