0

Can a conditional element a CodeElement in .NET? I scoured this page: http://msdn.microsoft.com/en-us/library/envdte.vscmelement(VS.80).aspx

Didn't find anything on that.

I am writing a macro/add-in to achieve the following: If the cursor is at a starting point of an if-condition statement, I want the corresponding End If statement to be highlighted. If the conditional elements(if,switch,etc..) can be represented as CodeElement type, then the job is easier.

seeker
  • 69
  • 1
  • 9

2 Answers2

1

I am afraid the answer is no. A code element has the granularity of a method or property (or you have some information if you are outside of a method). Inside a method, you don't know what kind of statement there is.

Sorry.

Timores
  • 14,439
  • 3
  • 46
  • 46
0

No, as Timores said, code element has the granularity of a method or property. To do what you need to do, you need the actual Abstract Syntax Tree of the code being viewed in the editor.

The easiest way to accomplish what you want is probably as a DXCore plugin - see the DXCore community pages and/or ask around there for more assistance. Once you have DXCore installed, you can look under the DevExpress menu in Visual Studio for the tree browser, where you'll see the Node of the Abstract Syntax Tree that represents your "if" statement, then look for code samples of how you can interact with it.

I should note that there is already pretty good brace-matching highlighting in Resharper, and that there is also the CodeKana VS plugin that highlights each type of control statement (if/while/etc) in different colors.

Omer Raviv
  • 11,409
  • 5
  • 43
  • 82