示例#1
0
        private static async Task <Document> RewriteArgumentList(
            Document document,
            ArgumentListSyntax argumentList,
            SyntaxTrivia openParenTrivia,
            SyntaxTrivia commaTrivia,
            SyntaxTrivia parameterTypeTrivia,
            CancellationToken cancellationToken)
        {
            var updatedArguments = argumentList.Arguments.Select(
                p => p.WithLeadingTrivia(parameterTypeTrivia));

            var separators = Enumerable.Repeat(
                SF.Token(SyntaxKind.CommaToken).WithTrailingTrivia(commaTrivia),
                argumentList.Arguments.Count() - 1);

            var updatedParameterList = SF.ArgumentList(
                SF.Token(SyntaxKind.OpenParenToken).WithTrailingTrivia(openParenTrivia),
                SF.SeparatedList(updatedArguments, separators),
                argumentList.CloseParenToken);

            var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);

            var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var newRoot     = root.ReplaceNode(argumentList, updatedParameterList);
            var newDocument = document.WithSyntaxRoot(newRoot);

            return(newDocument);
        }
示例#2
0
        public IEnumerable <StatementSyntax> GetInitialization()
        {
            yield return(SH.LocalDeclaration(SF.IdentifierName("var"), output,
                                             SF.ObjectCreationExpression(_stringBuilder.CreateSyntax())
                                             .WithArgumentList(SF.ArgumentList(SF.SeparatedList <ArgumentSyntax>()))));

            var bufferType = SF.ArrayType(SH.PredefinedType(SyntaxKind.CharKeyword),
                                          SF.SingletonList(SF.ArrayRankSpecifier(SF.SingletonSeparatedList((ExpressionSyntax)SH.Literal(BufferSize)))));

            yield return(SH.LocalDeclaration(SF.IdentifierName("var"), outputBuffer,
                                             SF.ArrayCreationExpression(bufferType)));

            yield return(SH.LocalDeclaration(SH.PredefinedType(SyntaxKind.IntKeyword), outputIndex, SH.Literal(0)));
        }
示例#3
0
 private static ArgumentListSyntax ToArgList(params ArgumentSyntax[] arguments) =>
 SF.ArgumentList(SF.SeparatedList(arguments));
示例#4
0
 public static ExpressionSyntax Call(this ExpressionSyntax expression, string instruction, IEnumerable <ExpressionSyntax> arguments)
 {
     return(SF.InvocationExpression(expression.Dot(instruction), SF.ArgumentList(SF.SeparatedList(
                                                                                     arguments.Select(x => SF.Argument(x))))));
 }
示例#5
0
 public static ExpressionSyntax Call(this ExpressionSyntax expression, SimpleNameSyntax instruction, params ExpressionSyntax[] arguments)
 {
     return(SF.InvocationExpression(expression.Dot(instruction), SF.ArgumentList(SF.SeparatedList(
                                                                                     arguments.Select(x => SF.Argument(x))))));
 }
示例#6
0
 public static ExpressionSyntax Invoke(this ExpressionSyntax expression, params ExpressionSyntax[] arguments)
 {
     return(SF.InvocationExpression(expression, SF.ArgumentList(SF.SeparatedList(
                                                                    arguments.Select(x => SF.Argument(x))))));
 }