Beispiel #1
0
        // MakeAbsolute(expr)   => expr
        // File(expr)           => expr
        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            node = (InvocationExpressionSyntax)base.VisitInvocationExpression(node).NotNull();

            if (node.GetIdentifierName() == "MakeAbsolute" ||
                node.GetIdentifierName() == "Directory" ||
                node.GetIdentifierName() == "File")
            {
                return(node.GetSingleArgument <ExpressionSyntax>());
            }

            if (node.GetIdentifierName() == "Combine")
            {
                return(CreateAbsolutePathExpression(node.Arguments()));
            }

            if (node.GetIdentifierName() == "GetFiles")
            {
                var expr = node.Arguments().Skip(1)
                           .Aggregate(
                    node.Arguments().FirstOrDefault()?.ToFullString(),
                    (f, s) => f + ".Concat(" + s.ToFullString() + ")");
                return(SyntaxFactory.ParseExpression(expr));
                // return InvocationExpression(
                //     MemberAccessExpression(
                //         SyntaxKind.SimpleMemberAccessExpression,
                //         ParenthesizedExpression(
                //             CastExpression(
                //                 ParseTypeName("AbsolutePath"),
                //                 ParenthesizedExpression(expressionSyntax))),
                //         IdentifierName("GlobFiles")));
            }

            if (node.GetIdentifierName() == "CleanDirectories")
            {
                var expressionSyntax = node.GetSingleArgument <ExpressionSyntax>();
                return(SyntaxFactory.InvocationExpression(
                           SyntaxFactory.MemberAccessExpression(
                               SyntaxKind.SimpleMemberAccessExpression,
                               expressionSyntax,
                               SyntaxFactory.IdentifierName("ForEach")))
                       .WithArguments(SyntaxFactory.IdentifierName("EnsureCleanDirectory")));
            }

            return(node);
        }