Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 文本前面的Visual Studio装饰会干扰选择 上周,我决定创建一个VisualStudio扩展名来测量C++代码覆盖率。基本上我每天都需要它。我想到的是可以找到的项目_C#_Visual Studio 2015_Visual Studio Sdk_Adornment - Fatal编程技术网

C# 文本前面的Visual Studio装饰会干扰选择 上周,我决定创建一个VisualStudio扩展名来测量C++代码覆盖率。基本上我每天都需要它。我想到的是可以找到的项目

C# 文本前面的Visual Studio装饰会干扰选择 上周,我决定创建一个VisualStudio扩展名来测量C++代码覆盖率。基本上我每天都需要它。我想到的是可以找到的项目,c#,visual-studio-2015,visual-studio-sdk,adornment,C#,Visual Studio 2015,Visual Studio Sdk,Adornment,大多数情况下,它运行良好。但是,我对装饰层有一些问题: 该项目的一个特点是创建(未)覆盖代码的突出显示。高亮显示本身工作正常,但似乎会干扰Visual Studio的选择代码: 负责突出显示的相关代码: private void HighlightCoverage(CoverageState[] coverdata, ITextViewLine line) { IWpfTextViewLineCollection textViewLines = view.TextViewLines;

大多数情况下,它运行良好。但是,我对装饰层有一些问题:

该项目的一个特点是创建(未)覆盖代码的突出显示。高亮显示本身工作正常,但似乎会干扰Visual Studio的选择代码:

负责突出显示的相关代码:

private void HighlightCoverage(CoverageState[] coverdata, ITextViewLine line)
{
    IWpfTextViewLineCollection textViewLines = view.TextViewLines;

    int lineno = 1 + view.TextSnapshot.GetLineNumberFromPosition(line.Extent.Start);

    CoverageState covered = lineno < coverdata.Length ?
                            coverdata[lineno] : CoverageState.Irrelevant;

    if (covered != CoverageState.Irrelevant)
    {
        SnapshotSpan span = new SnapshotSpan(view.TextSnapshot, 
                                    Span.FromBounds(line.Start, line.End));
        Geometry g = textViewLines.GetMarkerGeometry(span);
        if (g != null)
        {
            GeometryDrawing drawing = (covered == CoverageState.Covered) ?
                new GeometryDrawing(coveredBrush, coveredPen, g) :
                new GeometryDrawing(uncoveredBrush, uncoveredPen, g);

            drawing.Freeze();

            DrawingImage drawingImage = new DrawingImage(drawing);
            drawingImage.Freeze();

            Image image = new Image();
            image.Source = drawingImage;

            //Align the image with the top of the bounds of the text geometry
            Canvas.SetLeft(image, g.Bounds.Left);
            Canvas.SetTop(image, g.Bounds.Top);

            layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, 
                               span, null, image, null);
        }
    }
}
private void HighlightCoverage(CoverageState[]coverdata,ITextViewLine行)
{
IWpfTextViewLineCollection textViewLines=view.textViewLines;
int lineno=1+view.textsnashot.GetLineNumberFromPosition(line.Extent.Start);
CoverageState covered=行号
具有正确上下文的完整代码段可在此处找到:


问:有人能告诉我如何在背景上而不是在前景上渲染这些块吗?

7年前被问到,现在网上几乎没有关于装饰和扩展Visual Studio的信息

以下是您的操作方法:

  • 当您使用VS向导创建TextAdorment类实例(例如:右键单击project=>Add Item)时,您将收到两个文件:第一个是具有您选择的名称的类,另一个是

    [NameYouPicked]TextViewCreationListener.cs

  • 在解决方案资源管理器中找到该文件并将其打开

  • 转到您的装饰定义。应该是这样的:

  • PS:作为一项工作,我注意到你可以在图层上设置不透明度。虽然这是一个很好的解决办法,但我更愿意把图层放在背景中。很好的发现。这是7年来最好的答案…:-是的,你是对的,可惜文档太少了;这个框架确实很好,但是缺少文档使得它很难使用。好吧,一旦我确认这是正确的答案,我当然会。不过,考虑到花了7年的时间,我不明白为什么我现在要这么匆忙
    /// <summary>
    /// Defines the adornment layer for the adornment. This layer is ordered
    /// after the selection layer in the Z-order
    /// </summary>
    [Export(typeof(AdornmentLayerDefinition))]
    [Name("TextAdornment")]
    [Order(After = PredefinedAdornmentLayers.Selection, Before = PredefinedAdornmentLayers.Text)]
    private AdornmentLayerDefinition editorAdornmentLayer;
    
      [Order(Before = PredefinedAdornmentLayers.BraceCompletion)]