Esempio n. 1
0
        protected ExpressionSyntax GetNewExpression(ExpressionSyntax expression, NodeReplacement replacement)
        {
            var visitor = new MemberAccessExpressionsCSharpSyntaxVisitor();

            expression.Accept(visitor);
            var members = new LinkedList <MemberAccessExpressionSyntax>(visitor.Members);

            var current = members.Last;

            while (current != null)
            {
                if (replacement.IsValidNode(current))
                {
                    // extract custom data into the replacement object
                    replacement.ExtractValues(current.Value);

                    var oldNode = replacement.ComputeOld(current);
                    var newNode = replacement.ComputeNew(current);
                    return(expression.ReplaceNode(oldNode, newNode));
                }
                current = current.Previous;
            }

            throw new System.InvalidOperationException("should not get here");
        }