2

我正在使用 Visual Studio 2008 集成为 .NET 编写另一个代码覆盖工具。
一切都很顺利,除了一件事:我找不到突出显示某些代码块的方法。

我需要它来通知用户有关覆盖和未覆盖的块。
您可以在下一个屏幕截图中看到我想要的功能示例(来自本机 VS 代码覆盖工具集):

覆盖示例

有人可以为我提供一个代码片段,在代码视图窗口中突出显示文本吗?
也感谢与 VS2008 相关的适当 MSDN 文章的链接!

提前致谢。

4

2 回答 2

2

我找到了答案,请参见下面的代码:

// retrieving IVsTextManager and highlight id
DTE2 applicationObject = ...; // get it during addin init
Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)applicationObject;
Guid SID = typeof(SVsTextManager).GUID;
Guid IID = typeof(IVsTextManager).GUID;
IntPtr output;
serviceProvider.QueryService(ref SID, ref IID, out output);
IVsTextManager textManager = (IVsTextManager)Marshal.GetObjectForIUnknown(output);
int highlightID;
Guid highlightGuid = ...; // your highlighted text style guid
textManager.GetRegisteredMarkerTypeID(ref highlightGuid, out highlightID);

// highlighting text block in the active view
IVsTextView view;
int result = textManager.GetActiveView(0, null, out view);
IVsTextLines buffer;
view.GetBuffer(out buffer);
buffer.CreateLineMarker(highlightID, startLine, startColumn, endLine, endColumn, null, null);

更多示例可以在MetaScroll Visual Studio Addin中找到。

于 2009-12-29T05:55:29.583 回答
0

另一个例子,但对于 VS2010:http ://dotneteers.net/blogs/divedeeper/archive/2008/11/04/LearnVSXNowPart38.aspx

于 2010-09-19T06:55:48.487 回答