Ejemplo n.º 1
0
        public static bool TryGetAction(
            StatementSyntax statement,
            out Func <SyntaxNode, SemanticModel, SyntaxNode> action)
        {
            action = null;

            InvocationExpressionSyntax   outerMostInvocation;
            MemberAccessExpressionSyntax innerMostSelectAccess;
            List <ExpressionSyntax>      selectArgumentsList;

            bool isFound = LinqHelper.TryFindMethodSequence(
                statement,
                LinqHelper.SelectMethodName,
                NotLambdaOrLambdaWithInvocation,
                out outerMostInvocation,
                out innerMostSelectAccess,
                out selectArgumentsList);

            if (!isFound)
            {
                return(false);
            }

            action = (syntaxRoot, semanticModel) =>
            {
                var newInvocation = Merge(outerMostInvocation, innerMostSelectAccess, selectArgumentsList, semanticModel);

                syntaxRoot = syntaxRoot.ReplaceNode((SyntaxNode)outerMostInvocation, newInvocation);

                return(syntaxRoot.Format());
            };

            return(true);
        }
Ejemplo n.º 2
0
        public static bool TryGetAction(
            StatementSyntax statement,
            out Func <SyntaxNode, SemanticModel, SyntaxNode> action)
        {
            InvocationExpressionSyntax   outerMostInvocation;
            MemberAccessExpressionSyntax innerMostWhereAccess;
            List <ExpressionSyntax>      whereArgumentsList;

            bool isFound = LinqHelper.TryFindMethodSequence(
                statement,
                LinqHelper.WhereMethodName,
                null,
                out outerMostInvocation,
                out innerMostWhereAccess,
                out whereArgumentsList);

            if (!isFound)
            {
                action = null;
                return(false);
            }

            action = (syntaxRoot, semanticModel) =>
            {
                var newInvocation = Merge(
                    outerMostInvocation,
                    innerMostWhereAccess,
                    whereArgumentsList,
                    semanticModel);

                newInvocation = newInvocation
                                .WithTriviaFrom(outerMostInvocation)
                                .WithoutAnnotations(Simplifier.Annotation);

                syntaxRoot = syntaxRoot.ReplaceNode((SyntaxNode)outerMostInvocation, newInvocation);

                return(syntaxRoot.Format());
            };

            return(true);
        }