调试器可视化工具 [Visual Studio 2010] - System.Linq.Expressions.Expression - 不显示放大镜

发布于 2024-10-13 17:05:20 字数 1329 浏览 8 评论 0原文

我一直在尝试为 linq 表达式构建调试器可视化工具。

我知道已经存在一个,但我想创建自己的并添加附加功能。

我制作了这个快速原型。 放大镜不会显示;但是,如果我将一行代码更改为“Target = typeof(System.String)”,则会显示放大镜。

任何帮助将不胜感激。

using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;

[assembly: System.Diagnostics.DebuggerVisualizer(
    typeof(VisualizerPrototype.MyDebuggerVisualizer),
    typeof(VisualizerPrototype.MyDebuggerVisualizerObjectSource),
    Target = typeof(System.Linq.Expressions.Expression),
    Description = "My Debugger Visualizer")]
namespace VisualizerPrototype
{
    public class MyDebuggerVisualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            var text = string.Empty;
            using (var sr = new StreamReader(objectProvider.GetData()))
            {
                text = sr.ReadToEnd();
            }

            MessageBox.Show(text);
        }
    }

    public class MyDebuggerVisualizerObjectSource : VisualizerObjectSource
    {
        public override void GetData(object target, System.IO.Stream outgoingData)
        {
            var sw = new StreamWriter(outgoingData);
            sw.WriteLine("YO");
            sw.Flush();
        }
    }
}

I have been trying to build a debugger visualizer for a linq Expression.

I know one exists already, but I would like to create my own and add additional functionality.

I made this quick prototype.
The magnifying glass will not show up; however, if I change the one line of code to "Target = typeof(System.String)", the magnifying glass shows up.

Any help would be appreciated.

using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;

[assembly: System.Diagnostics.DebuggerVisualizer(
    typeof(VisualizerPrototype.MyDebuggerVisualizer),
    typeof(VisualizerPrototype.MyDebuggerVisualizerObjectSource),
    Target = typeof(System.Linq.Expressions.Expression),
    Description = "My Debugger Visualizer")]
namespace VisualizerPrototype
{
    public class MyDebuggerVisualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            var text = string.Empty;
            using (var sr = new StreamReader(objectProvider.GetData()))
            {
                text = sr.ReadToEnd();
            }

            MessageBox.Show(text);
        }
    }

    public class MyDebuggerVisualizerObjectSource : VisualizerObjectSource
    {
        public override void GetData(object target, System.IO.Stream outgoingData)
        {
            var sw = new StreamWriter(outgoingData);
            sw.WriteLine("YO");
            sw.Flush();
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

香草可樂 2024-10-20 17:05:20

对于将来读到这篇文章的人来说,我发现了问题的根源。
调试器可视化工具的目标类型必须是运行时类型而不是继承类型。

Target = typeof(System.Linq.Expressions.ConstantExpression)
Expression expr = Expression.Constant(1); //visualizer shows up

Target = typeof(System.Linq.Expressions.Expression)
Expression expr = Expression.Constant(1); //visualizer doesn't show up

For anybody reading this in the future, I discovered the source of my problem.
The target type for a debugger visualizer must be the runtime type and not an inherited type.

Target = typeof(System.Linq.Expressions.ConstantExpression)
Expression expr = Expression.Constant(1); //visualizer shows up

Target = typeof(System.Linq.Expressions.Expression)
Expression expr = Expression.Constant(1); //visualizer doesn't show up
你又不是我 2024-10-20 17:05:20

尝试这个用于 VB:

Target = GetType(Expression(Of ))

或这个用于 C#:

Target = typeof(Expression<>)

Try this one for VB:

Target = GetType(Expression(Of ))

Or this one for C#:

Target = typeof(Expression<>)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文