// Display deserialized SyntaxTree / SyntaxNode / SyntaxToken / SyntaxTrivia.
        internal void Display(SyntaxTransporter transporter)
        {
            if (transporter != null)
            {
                var          node         = transporter.GetSyntaxNode();
                const string ErrorMessage =
                    @"The visualizer failed to correctly serialize / deserialize the
object that you are trying to visualize. The information
currently being displayed in the visualizer may be incorrect.

The root cause could be one of the following -

1. You are trying to visualize a 'top-level' SyntaxToken /
SyntaxTrivia that was generated using Roslyn Syntax Factory
Methods. This is not supported currently.

- OR -

2. There is a bug in Roslyn Syntax APIs that is causing the
serialization / deserialization to fail.";

                if (node == null)
                {
                    HandleError(ErrorMessage);
                }
                else
                {
                    // Populate textbox with source code.
                    codeTextBox.Text = node.ToFullString();

                    // Populate treeview.
                    syntaxVisualizer.DisplaySyntaxNode(node, transporter.SourceLanguage);

                    // In the textbox, select the text corresponding to the SyntaxNode / SyntaxToken /
                    // SyntaxTrivia being debugged.
                    SelectText(transporter.ItemSpan.Start, transporter.ItemSpan.Length);

                    // In the treeview, select the SyntaxNode / SyntaxToken / SyntaxTrivia being debugged.
                    if (!syntaxVisualizer.NavigateToBestMatch(transporter.ItemSpan,
                                                              transporter.ItemKind,
                                                              transporter.ItemCategory,
                                                              highlightMatch: true,
                                                              highlightLegendDescription: "Under Inspection"))
                    {
                        // Display error message if the SyntaxNode / SyntaxToken / SyntaxTrivia
                        // being debugged was not found in the tree.
                        HandleError(ErrorMessage);
                    }
                }
            }
        }
        // Display deserialized SyntaxTree / SyntaxNode / SyntaxToken / SyntaxTrivia.
        internal void Display(SyntaxTransporter transporter)
        {
            if (transporter != null)
            {
                var node = transporter.GetSyntaxNode();
                const string ErrorMessage =
            @"The visualizer failed to correctly serialize / deserialize the
            object that you are trying to visualize. The information
            currently being displayed in the visualizer may be incorrect.

            The root cause could be one of the following -

            1. You are trying to visualize a 'top-level' SyntaxToken /
            SyntaxTrivia that was generated using Roslyn Syntax Factory
            Methods. This is not supported currently.

            - OR -

            2. There is a bug in Roslyn Syntax APIs that is causing the
            serialization / deserialization to fail.";

                if (node == null)
                {
                    HandleError(ErrorMessage);
                }
                else
                {
                    // Populate textbox with source code.
                    codeTextBox.Text = node.ToFullString();

                    // Populate treeview.
                    syntaxVisualizer.DisplaySyntaxNode(node, transporter.SourceLanguage);

                    // In the textbox, select the text corresponding to the SyntaxNode / SyntaxToken /
                    // SyntaxTrivia being debugged.
                    SelectText(transporter.ItemSpan.Start, transporter.ItemSpan.Length);

                    // In the treeview, select the SyntaxNode / SyntaxToken / SyntaxTrivia being debugged.
                    if (!syntaxVisualizer.NavigateToBestMatch(transporter.ItemSpan,
                                                              transporter.ItemKind,
                                                              transporter.ItemCategory,
                                                              highlightMatch: true,
                                                              highlightLegendDescription: "Under Inspection"))
                    {
                        // Display error message if the SyntaxNode / SyntaxToken / SyntaxTrivia
                        // being debugged was not found in the tree.
                        HandleError(ErrorMessage);
                    }
                }
            }
        }
Exemple #3
0
        public override void GetData(object target, Stream outgoingData)
        {
            SyntaxTransporter transporter = null;

            if (target != null)
            {
                if (target is CommonSyntaxTree)
                {
                    var tree = (CommonSyntaxTree)target;
                    transporter = new SyntaxTransporter(tree);
                }
                else if (target is CommonSyntaxNodeOrToken)
                {
                    var nodeOrToken = (CommonSyntaxNodeOrToken)target;
                    transporter = new SyntaxTransporter(nodeOrToken);
                }
                else if (target is CommonSyntaxNode)
                {
                    var node = (CommonSyntaxNode)target;
                    transporter = new SyntaxTransporter(node);
                }
                else if (target is CommonSyntaxToken)
                {
                    var token = (CommonSyntaxToken)target;
                    transporter = new SyntaxTransporter(token);
                }
                else if (target is CommonSyntaxTrivia)
                {
                    var trivia = (CommonSyntaxTrivia)target;
                    transporter = new SyntaxTransporter(trivia);
                }
                else if (target is CSharp.SyntaxNodeOrToken)
                {
                    var nodeOrToken = (CSharp.SyntaxNodeOrToken)target;
                    transporter = new SyntaxTransporter(nodeOrToken);
                }
                else if (target is CSharp.SyntaxToken)
                {
                    var token = (CSharp.SyntaxToken)target;
                    transporter = new SyntaxTransporter(token);
                }
                else if (target is CSharp.SyntaxTrivia)
                {
                    var trivia = (CSharp.SyntaxTrivia)target;
                    transporter = new SyntaxTransporter(trivia);
                }
                else if (target is VisualBasic.SyntaxNodeOrToken)
                {
                    var nodeOrToken = (VisualBasic.SyntaxNodeOrToken)target;
                    transporter = new SyntaxTransporter(nodeOrToken);
                }
                else if (target is VisualBasic.SyntaxToken)
                {
                    var token = (VisualBasic.SyntaxToken)target;
                    transporter = new SyntaxTransporter(token);
                }
                else if (target is VisualBasic.SyntaxTrivia)
                {
                    var trivia = (VisualBasic.SyntaxTrivia)target;
                    transporter = new SyntaxTransporter(trivia);
                }
            }

            Serialize(outgoingData, transporter);
        }
        public override void GetData(object target, Stream outgoingData)
        {
            SyntaxTransporter transporter = null;

            if (target != null)
            {
                if (target is CommonSyntaxTree)
                {
                    var tree = (CommonSyntaxTree)target;
                    transporter = new SyntaxTransporter(tree);
                }
                else if (target is CommonSyntaxNodeOrToken)
                {
                    var nodeOrToken = (CommonSyntaxNodeOrToken)target;
                    transporter = new SyntaxTransporter(nodeOrToken);
                }
                else if (target is CommonSyntaxNode)
                {
                    var node = (CommonSyntaxNode)target;
                    transporter = new SyntaxTransporter(node);
                }
                else if (target is CommonSyntaxToken)
                {
                    var token = (CommonSyntaxToken)target;
                    transporter = new SyntaxTransporter(token);
                }
                else if (target is CommonSyntaxTrivia)
                {
                    var trivia = (CommonSyntaxTrivia)target;
                    transporter = new SyntaxTransporter(trivia);
                }
                else if (target is CSharp.SyntaxNodeOrToken)
                {
                    var nodeOrToken = (CSharp.SyntaxNodeOrToken)target;
                    transporter = new SyntaxTransporter(nodeOrToken);
                }
                else if (target is CSharp.SyntaxToken)
                {
                    var token = (CSharp.SyntaxToken)target;
                    transporter = new SyntaxTransporter(token);
                }
                else if (target is CSharp.SyntaxTrivia)
                {
                    var trivia = (CSharp.SyntaxTrivia)target;
                    transporter = new SyntaxTransporter(trivia);
                }
                else if (target is VisualBasic.SyntaxNodeOrToken)
                {
                    var nodeOrToken = (VisualBasic.SyntaxNodeOrToken)target;
                    transporter = new SyntaxTransporter(nodeOrToken);
                }
                else if (target is VisualBasic.SyntaxToken)
                {
                    var token = (VisualBasic.SyntaxToken)target;
                    transporter = new SyntaxTransporter(token);
                }
                else if (target is VisualBasic.SyntaxTrivia)
                {
                    var trivia = (VisualBasic.SyntaxTrivia)target;
                    transporter = new SyntaxTransporter(trivia);
                }
            }

            Serialize(outgoingData, transporter);
        }