private MemberDeclarationSyntax CreateInvokeExecuteAsyncMethod(
        string parameterTypeName,
        string resultTypeName,
        bool hasParameters)
    {
        var arguments = hasParameters
            ? new SyntaxNodeOrToken[]
        {
            SyntaxParameterFactory.Create(parameterTypeName, "parameters"),
            SyntaxTokenFactory.Comma(),
            SyntaxParameterFactory.Create(nameof(CancellationToken), nameof(CancellationToken).EnsureFirstCharacterToLower()),
        }
            : new SyntaxNodeOrToken[]
        {
            SyntaxParameterFactory.Create(nameof(CancellationToken), nameof(CancellationToken).EnsureFirstCharacterToLower()),
        };

        var bodyBlockSyntaxStatements = CreateBodyBlockSyntaxStatements(resultTypeName);

        return(SyntaxFactory.MethodDeclaration(
                   SyntaxFactory.GenericName(SyntaxFactory.Identifier(nameof(Task)))
                   .WithTypeArgumentList(
                       SyntaxFactory.TypeArgumentList(
                           SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                               SyntaxFactory.IdentifierName(EndpointResultTypeName)))),
                   SyntaxFactory.Identifier("InvokeExecuteAsync"))
               .WithModifiers(SyntaxTokenListFactory.PrivateAsyncKeyword())
               .WithParameterList(
                   SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList <ParameterSyntax>(arguments)))
               .WithBody(
                   SyntaxFactory.Block(bodyBlockSyntaxStatements)));
    }
Ejemplo n.º 2
0
        private MemberDeclarationSyntax CreateInvokeExecuteAsyncMethod(string parameterTypeName, string resultTypeName, bool hasParameters)
        {
            var arguments = hasParameters
                ? new SyntaxNodeOrToken[]
            {
                SyntaxParameterFactory.Create(parameterTypeName, "parameters"),
                SyntaxTokenFactory.Comma(),
                SyntaxParameterFactory.Create(nameof(CancellationToken), nameof(CancellationToken).EnsureFirstCharacterToLower())
            }
                : new SyntaxNodeOrToken[]
            {
                SyntaxParameterFactory.Create(nameof(CancellationToken), nameof(CancellationToken).EnsureFirstCharacterToLower())
            };

            return(SyntaxFactory.MethodDeclaration(
                       SyntaxFactory.GenericName(SyntaxFactory.Identifier(nameof(Task)))
                       .WithTypeArgumentList(SyntaxTypeArgumentListFactory.CreateWithOneItem(resultTypeName)),
                       SyntaxFactory.Identifier("InvokeExecuteAsync"))
                   .WithModifiers(SyntaxTokenListFactory.PrivateAsyncKeyword())
                   .WithParameterList(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList <ParameterSyntax>(arguments)))
                   .WithBody(SyntaxFactory.Block(SyntaxThrowStatementFactory.CreateNotImplementedException())));
        }