public object Output(object obj)
        {
            // We don't visualize null
            if (obj == null)
            {
                return(null);
            }

            // Primitive types and strings are visualized as ToString
            if (obj.GetType().IsPrimitive || obj is string)
            {
                return(obj.ToString());
            }

            // UI elements should be resurfaced back.
            if (obj is UIElement)
            {
                return(obj);
            }

            // All other should be visualized in a table
            IResultVisualizer resultTreeItem = ResultVisualizer.Create(obj, obj.GetType(), "result", null, this);

            resultTreeItem.Initialize();
            return(new LazyUIResult(() => Visualize(resultTreeItem)));
        }
Esempio n. 2
0
        public object Output(object obj)
        {
            // We don't visualize null
            if (obj == null)
            {
                return(null);
            }

            // Primitive types and strings are visualized as ToString
            if (obj.GetType().IsPrimitive || obj is string)
            {
                return(obj.ToString());
            }

            // UI elements should be resurfaced back.
            if (obj is UIElement)
            {
                return(obj);
            }

            // Drawing objects should be resurfaced back.
            IDrawing drawing = obj as IDrawing;

            if (drawing != null)
            {
                return(new LazyUIResult(() => new DrawingViewer(drawing)));
            }

            // All other should be visualized in a table
            IResultVisualizer resultTreeItem = ResultVisualizer.Create(obj, obj.GetType(), "result", CompletionDataType.Unknown, this);

            resultTreeItem.Initialize();

            // Check if we can also represent resulting object as a drawing
            IDrawingVisualizerObject drawingVisualizerObject = obj as IDrawingVisualizerObject;

            if (drawingVisualizerObject != null && drawingVisualizerObject.CanVisualize())
            {
                Graphics graphics = new Graphics(dispatcher);

                drawing = drawingVisualizerObject.CreateDrawing(graphics);
            }

            if (drawing != null)
            {
                // Create panel that will hold both elements.
                return(new LazyUIResult(() =>
                {
                    StackPanel panel = new StackPanel();

                    panel.Orientation = Orientation.Vertical;
                    panel.Children.Add(Visualize(resultTreeItem));
                    panel.Children.Add(new DrawingViewer(drawing));
                    return panel;
                }));
            }

            // Check if it is console printer
            if (obj is IConsoleVisualizer consoleVisualizer)
            {
                consoleVisualizer.PrintOnConsole();
                return(null);
            }

            return(new LazyUIResult(() => Visualize(resultTreeItem)));
        }