简体   繁体   English

.NET中的条件元素是CodeElement吗?

[英]Is a conditional element a CodeElement in .NET?

Can a conditional element a CodeElement in .NET? .NET中的条件元素可以是CodeElement吗? I scoured this page: http://msdn.microsoft.com/en-us/library/envdte.vscmelement(VS.80).aspx 我浏览了以下页面: http : //msdn.microsoft.com/zh-cn/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-condition语句的起点,则希望突出显示相应的End If语句。 If the conditional elements(if,switch,etc..) can be represented as CodeElement type, then the job is easier. 如果条件元素(if,switch等)可以表示为CodeElement类型,则工作会更容易。

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. 抱歉。

No, as Timores said, code element has the granularity of a method or property. 不,正如Timores所说,代码元素具有方法或属性的粒度。 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. 实现所需功能的最简单方法可能是使用DXCore插件-请参阅DXCore社区页面和/或在此附近寻求更多帮助。 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. 一旦安装了DXCore,就可以在Visual Studio的DevExpress菜单下查看树浏览器,在树浏览器中,您将看到代表“ if”语句的抽象语法树的节点,然后查找如何执行的代码示例。与之互动。

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. 我应该注意,Resharper中已经有相当不错的括号匹配突出显示,并且还有CodeKana VS插件以不同的颜色突出显示了每种控制语句(if / while / etc)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM