Esempio n. 1
0
        private static InvocationExpressionSyntax ReplaceInvocationsInArguments(
            InvocationExpressionSyntax invocation,
            InvocationReplacer replacer)
        {
            var newArguments = new SeparatedSyntaxList <ArgumentSyntax>();

            foreach (var argument in invocation.ArgumentList.Arguments)
            {
                var newArgument = (ArgumentSyntax)argument.Accept(replacer);
                newArguments = newArguments.Add(newArgument);
            }

            return(SyntaxFactory.InvocationExpression(
                       invocation.Expression,
                       SyntaxFactory.ArgumentList(newArguments)));
        }
Esempio n. 2
0
        private static InvocationExpressionSyntax SplitFunctionComposition(
            InvocationExpressionSyntax selectInvocation,
            SimpleLambdaExpressionSyntax projection,
            InvocationExpressionSyntax[] invocationStack,
            SemanticModel semanticModel)
        {
            var lambdaParameter = projection.Parameter;
            var parameterName   = lambdaParameter.Identifier.Text;
            var parameterSymbol = semanticModel.GetDeclaredSymbol(lambdaParameter);

            Func <InvocationExpressionSyntax, bool> isNeedToReplaceInvocation = i =>
                                                                                DataFlowAnalysisHelper.IsIdentifierReferencedIn(
                parameterName,
                parameterSymbol,
                semanticModel,
                i);

            var newSelectInvocation = ExtendedSyntaxFactory.MakeInvocationWithLambdaArgument(
                selectInvocation.Expression,
                lambdaParameter,
                invocationStack[0]);

            var invocationReplacer = new InvocationReplacer(
                isNeedToReplaceInvocation,
                SyntaxFactory.IdentifierName(parameterName));

            for (int i = 1; i < invocationStack.Length; ++i)
            {
                var innerInvocation = invocationStack[i];

                var processedInnerInvocation = ReplaceInvocationsInArguments(
                    innerInvocation,
                    invocationReplacer);

                var memberAccess = SyntaxFactory.MemberAccessExpression(
                    SyntaxKind.SimpleMemberAccessExpression,
                    newSelectInvocation,
                    SyntaxFactory.IdentifierName(LinqHelper.SelectMethodName));

                newSelectInvocation = ExtendedSyntaxFactory.MakeInvocationWithLambdaArgument(
                    memberAccess,
                    lambdaParameter,
                    processedInnerInvocation);
            }

            return(newSelectInvocation.WithTriviaFrom(selectInvocation));
        }