3

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();
        }
    }
}
BSick7
  • 575
  • 4
  • 13

2 Answers2

2

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
BSick7
  • 575
  • 4
  • 13
0

Try this one for VB:

Target = GetType(Expression(Of ))

Or this one for C#:

Target = typeof(Expression<>)
Andro Selva
  • 53,910
  • 52
  • 193
  • 240