如何在Visual Studio中确定当前插入符位置是一个注释块? [英] How to determine in Visual Studio that the current caret position is in a comment block?

查看:127
本文介绍了如何在Visual Studio中确定当前插入符位置是一个注释块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Visual Studio代码编辑器(C / C ++或C#),以确定编程当前插入符位置是一个注释块内(//之后或之间/ * * /)?我试图用IContentType这样的:

Is there a way to determine programmatically in a Visual Studio code editor ( C/C++ or C# ) that the current caret position is within a comment block ( after "//" or between /* */ )? I tried to use IContentType like this:

if ( m_textView.TextBuffer.ContentType.TypeName == "comment" ) 

但似乎ContentType.BaseTypes仅包含更广泛的内容类型(如文,代码, C / C ++)与整个文件

but it seems that ContentType.BaseTypes contain only more general content types (like "text", "code", "C/C++") relating to the whole file.

推荐答案

您应该能够使用的 IClassifierAggregatorService 访问用于语法在编辑器中突出了分类。如果你不打我吧,我晚上发布一个更完整的例子显示的提取 IClassificationType 尖号下的文字。

You should be able to use the IClassifierAggregatorService to access the classifications used for syntax highlighting in the editor. If you don't beat me to it, I'll post a more complete example this evening showing the extraction of the IClassificationType of the text under the caret.

这篇关于如何在Visual Studio中确定当前插入符位置是一个注释块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆