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!
The
CodeElementinterface has the propertiesStartPointandEndPointwhich represent the start and end of the element within the buffer. These contain the Line Number / Column which can be passed to methods likeIVsTextLines.GetLineTextand give you back the value you’re looking for.To get the
IVsTextLinesfor a givenCodeElementyou can do the following