我已经制作了一个DebuggerVisualizer来显示一个抽象Puzzle类的简单图像 - 我遇到的问题是,在我的测试应用程序中,它只是创建一个拼图并调用TestShowVisualizer(),图像在屏幕上正确显示。但是,在调试项目并将鼠标悬停在变量上时,没有可视化器(或放大镜图标)
public abstract class Puzzle
{
// Lots of properties and methods here //
public static Puzzle Load(StreamReader sr)
{
// Reads the stream reader and creates the correct derived class
}
public abstract Image GenerateNet();
}
[DebuggerVisualizer(typeof(PuzzleVisualizer), typeof(PuzzleVisualizerObjectSource), Description = "Image Visualizer", Target = typeof(Puzzle))]
public class PuzzleVisualizer : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
{
var puz = Puzzle.Load(new StreamReader(objectProvider.GetData()));
var image = puz.GenerateNet();
var form = new Form
{
Text = $"Width: {image.Width}, Height: {image.Height}",
ClientSize = new Size(image.Width, image.Height),
FormBorderStyle = FormBorderStyle.FixedToolWindow
};
var pictureBox = new PictureBox
{
Image = image,
Parent = form,
Dock = DockStyle.Fill
};
windowService.ShowDialog(form);
}
public static void TestShowVisualizer(object objectToVisualize)
{
var visualizerHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(PuzzleVisualizer), typeof(PuzzleVisualizerObjectSource));
visualizerHost.ShowVisualizer();
}
}
我制作了一个测试应用程序,其中所有用于制作可视化工具的示例也都使用了:
public class Program
{
public static void Main(string[] args)
{
var p = new Cube222();
p.Setup();
PuzzleVisualizer.TestShowVisualizer(p);
return;
}
}
可视化工具在调用TestShowVisualizer()时有效,但不仅用于一般调试。
我确保visualizer类在它自己的DLL中,并且它被复制到C:\ Program Files \ Microsoft Visual Studio \ 2017 \ Community \ Common7 \ Packages \ Debugger \ Visualizers
关于我做错的任何想法?
答案 0 :(得分:1)
我找到了原因,这是因为DebuggerVisualizer
属性需要应用于命名空间而不是类。
所以
using Microsoft.VisualStudio.DebuggerVisualizers;
using PuzzleExplorer.Visualizers;
[assembly:DebuggerVisualizer(typeof(PuzzleVisualizer), typeof(PuzzleVisualizerObjectSource), Description = "Puzzle Visualizer", Target = typeof(Puzzle))]
namespace PuzzleExplorer.Visualizers
{
public class PuzzleVisualizer : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
{
// code
}
}
}
我阅读了教程,它确实清楚但我却错过了它。
在using语句之后但在名称空间MyFirstVisualizer之前,将以下属性代码添加到DebuggerSide.cs: