如何在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.