Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:08:28+00:00 2026-06-08T16:08:28+00:00

Solved: mike z was right, I wasn’t calling the base properly to continue the

  • 0

Solved: mike z was right, I wasn’t calling the base properly to continue the recursion. Thanks, mike

I’m doing some code rewriting using Roslyn, via implementing a SyntaxRewriter.

The odd thing I’m running into is that when overriding SyntaxNode.VisitInvocationExpression(InvocationExpressionSyntax), it does NOT visit all InvocationExpressionSyntax nodes in the tree. (I assume it’s the same for all SyntaxNode types)

For example, given this invocation expression:

  controller.Add(5, 6).ToString();

it only Visits the node for the entire expression, even though there are 2 invocations there.

While I can certainly write a recursive function or similar to parse child/nested InvocationExpression nodes, this seems inconsistent and inconvenient.
Why isn’t it visiting all nodes of * type in the entire tree?

Here’s my override:

    public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
    {
        IdentifierNameSyntax ident = node.ChildNodes().OfType<IdentifierNameSyntax>().FirstOrDefault();
        if (ident == null)
            return node;//In my test case, the example above returns here when it's node is encountered.  Shouldn't this then allow the walker to continue deeper into the node,
                        // finding the deeper nested Invocations?

        string name = ident.PlainName;
        if (!TempStore.ConstructedInvocations.ContainsKey(name))//not replacing this then
            return node;

        InvocationExpressionSyntax newInvocation = ((InvocationExpressionSyntax)TempStore.ConstructedInvocations[name]).WithArgumentList(node.ArgumentList);
        return newInvocation;
    }

Stepping through that code in debug confirms that the InvocationExpressionNode for controller.Add(5, 6).ToString(); does indeed have child InvocationExpressionNodes nested inside.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:08:29+00:00Added an answer on June 8, 2026 at 4:08 pm

    I was playing with the Roslyn API and had a similar problem. The Visit method is being called recursively in the base class implementation of the Visit* methods. Once you override one of those you are taking responsibility for Visiting all of the child nodes. You can do this by either calling the base.Visit* method on the node you are rewriting or calling Visit on each of the child nodes.

    Here is some sample code where I rewrite the logical operators, && and ||, by swapping them. I construct a new node with a different operator and then call the base.VisitBinaryExpression to make sure all child nodes are visited. Otherwise, we would only rewrite part of an expression like var1 && (var2 || var3). Another possible implementation would be to call Visit on node.Left and node.Right and then construct the new node from those results.

    public class LogicalOperatorRewriter : SyntaxRewriter
    {
        public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
        {
            SyntaxKind newExpressionKind = GetNewKind(node.Kind);
            BinaryExpressionSyntax newNode = (BinaryExpressionSyntax)Syntax.BinaryExpression(newExpressionKind, left: node.Left, right: node.Right).Format().GetFormattedRoot();
            return base.VisitBinaryExpression(newNode);
        }
    
        private SyntaxKind GetNewKind(SyntaxKind kind)
        {
            switch (kind)
            {
                case SyntaxKind.LogicalAndExpression:
                    return SyntaxKind.LogicalOrExpression;
                case SyntaxKind.LogicalOrExpression:
                    return SyntaxKind.LogicalAndExpression;
                default: return kind;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Solved Problem: to show external code dependency by submodules: Thanks to VonC ! Current
SOLVED: Crap... why is it always you figure something out right AFTER you finally
SOLVED. Code has been edited to reflect solution. Given the following GridView : <asp:GridView
SOLVED I misspelled the property department -> Department. Thanks for the answers and a
SOLVED: View the answer below marked SOLVED. Thanks. I am trying to download a
SOLVED I'm writing a code for making Set by linked lists in C++ with
(Solved) Thanks to NetCat: it was a UI XML problem :) Today I have
SOLVED!!!! Thanks for your help I'm kinda lost here, I'd like to remove all
[Solved] Writing parsing code is a trap. A line with 15 spaces will have
(SOLVED) I'm building an application that can create some of its control dynamically, based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.