Visual Studio 自定义可视化调试工具已有大量文章介绍,这里不再啰嗦。如果不懂建议看看https://www.cnblogs.com/cyq1162/p/4551652.html
本人也胡乱弄了个可视化调试 显示一组中间计算曲线,开始一切顺利,技术难度也不大。
代码及运行效果如下:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using FirstLineTamping.Infrastructure.Measure;
using LineView;
using Microsoft.VisualStudio.DebuggerVisualizers;
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(FirstLineTamping.Infrastructure.Measure.MeasSet), Description = "TMGC MeasSet Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(FirstLineTamping.Infrastructure.Measure.VerschArray), Description = "TMGC VerschArray Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(FirstLineTamping.Contract.Entities.Offsets.TrackOffset), Description = "TMGC TrackOffset Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(List<MeasRecord>), Description = "TMGC List<MeasRecord> Visualizer")]
[assembly: System.Diagnostics.DebuggerVisualizer(typeof(TMGC_DV.TMGC_Visualizer), typeof(VisualizerObjectSource), Target = typeof(FittingMeasure.PosValueArray), Description = "TMGC PosValueArray Visualizer")]
namespace TMGC_DV
{
public class TMGC_Visualizer : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
{
var s = objectProvider.GetObject();
Db_Form f = new Db_Form();
Debug.WriteLine("DialogDebuggerVisualizer :" + objectProvider.ToString ());
if (s is FirstLineTamping.Infrastructure.Measure.MeasSet)
{
f.AddMeasGrph(s as FirstLineTamping.Infrastructure.Measure.MeasSet);
f.Text = "Measure.MeasSet";
}
if (s is FirstLineTamping.Infrastructure.Measure.VerschArray)
{
f.AddMeasGrph(s as FirstLineTamping.Infrastructure.Measure.VerschArray);
}
if (s is FirstLineTamping.Contract.Entities.Offsets.TrackOffset)
{
f.AddMeasGrph(s as FirstLineTamping.Contract.Entities.Offsets.TrackOffset);
}
if (s is List<MeasRecord> )
{
f.AddMeasGrph(s as List<MeasRecord>);
}
if (s is FittingMeasure.PosValueArray)
{
f.AddMeasGrph(s as FittingMeasure.PosValueArray);
f.Text = "PosValueArray";
}
f.ShowDialog();
}
public static void TestShowVisualizer(object objectToVisualize)
{
VisualizerDevelopmentHost visualizerHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(TMGC_Visualizer));
visualizerHost.ShowVisualizer();
}
}
}
运行效果
昨天更新了到了 Microsoft Visual Studio Professional 2019 版本 16.4.5
我的工具就不会工作了,总是显示:
在网上搜索半天发现:Visual Studio Professional 2019 要求被调试对象是 “可信任"程序,否则不能使用自定义调试工具!
折腾半天!