Visualizer debugger [Visual Studio 2010] - System.Linq.Expressions.Expression - does not show a magnifying glass

I am trying to create a debugger visualizer for a linq expression.

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

I made this quick prototype. A magnifying glass will not be displayed; however, if I change one line of code to "Target = typeof (System.String)", a magnifying glass appears.

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();
        }
    }
}
+3
source share
2 answers

For anyone reading this in the future, I have discovered the source of my problem. The target type for the debugger visualizer must be a runtime type, 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
+2

VB:

Target = GetType(Expression(Of ))

#:

Target = typeof(Expression<>)
0

Source: https://habr.com/ru/post/1787165/


All Articles