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

发布于 2024-10-03 23:56:18 字数 354 浏览 0 评论 0原文

.NET 中的条件元素可以是 CodeElement 吗? 我浏览了这个页面: http://msdn.microsoft.com/en- us/library/envdte.vscmelement(VS.80).aspx

没有找到任何内容。

我正在编写一个宏/插件来实现以下目标: 如果光标位于 if 条件语句的起点,我希望突出显示相应的 End If 语句。 如果条件元素(if、switch 等)可以表示为 CodeElement 类型,那么工作会更容易。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

開玄 2024-10-10 23:56:18

恐怕答案是否定的。代码元素具有方法或属性的粒度(或者如果您在方法之外,则您有一些信息)。在方法内部,您不知道有什么样的语句。

对不起。

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.

差↓一点笑了 2024-10-10 23:56:18

不,正如 Timores 所说,代码元素具有方法或属性的粒度。
要执行您需要执行的操作,您需要在编辑器中查看的代码的实际抽象语法树。

实现您想要的最简单的方法可能是作为 DXCore 插件 - 请参阅 DXCore 社区页面和/或向周围寻求更多帮助。安装 DXCore 后,您可以在 Visual Studio 中的 DevExpress 菜单下查找树浏览器,您将在其中看到代表“if”语句的抽象语法树的节点,然后查找代码示例,了解如何与其互动。

我应该注意到,Resharper 中已经有相当好的大括号匹配突出显示,并且还有 CodeKana VS插件以不同的颜色突出显示每种类型的控制语句(if/while/etc)。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文