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( SyntaxFactory.TokenList( SyntaxFactory.Token( CreatePragmaWarningCodeStyle1998(true), SyntaxKind.PrivateKeyword, SyntaxFactory.TriviaList()), SyntaxFactory.Token(SyntaxKind.AsyncKeyword))) .WithParameterList(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList <ParameterSyntax>(arguments))) .WithBody( SyntaxFactory.Block(SyntaxThrowStatementFactory.CreateNotImplementedException()) .WithOpenBraceToken( SyntaxFactory.Token( CreatePragmaWarningCodeStyle1998(false), SyntaxKind.OpenBraceToken, SyntaxFactory.TriviaList())))); }
private MemberDeclarationSyntax CreateExecuteAsyncMethod(string parameterTypeName, string resultTypeName, bool hasParameters) { var arguments = hasParameters ? new SyntaxNodeOrToken[] { SyntaxParameterFactory.Create(parameterTypeName, "parameters"), SyntaxTokenFactory.Comma(), SyntaxParameterFactory.Create(nameof(CancellationToken), nameof(CancellationToken).EnsureFirstCharacterToLower()) .WithDefault(SyntaxFactory.EqualsValueClause( SyntaxFactory.LiteralExpression(SyntaxKind.DefaultLiteralExpression, SyntaxTokenFactory.DefaultKeyword()))), } : new SyntaxNodeOrToken[] { SyntaxParameterFactory.Create(nameof(CancellationToken), nameof(CancellationToken).EnsureFirstCharacterToLower()) .WithDefault(SyntaxFactory.EqualsValueClause( SyntaxFactory.LiteralExpression(SyntaxKind.DefaultLiteralExpression, SyntaxTokenFactory.DefaultKeyword()))), }; var codeBody = hasParameters ? SyntaxFactory.Block( SyntaxIfStatementFactory.CreateParameterArgumentNullCheck("parameters"), SyntaxFactory.ReturnStatement( SyntaxFactory.InvocationExpression( SyntaxFactory.IdentifierName("InvokeExecuteAsync")) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SeparatedList <ArgumentSyntax>( new SyntaxNodeOrToken[] { SyntaxFactory.Argument(SyntaxFactory.IdentifierName("parameters")), SyntaxTokenFactory.Comma(), SyntaxFactory.Argument(SyntaxFactory.IdentifierName(nameof(CancellationToken).EnsureFirstCharacterToLower())), }))))) : SyntaxFactory.Block( SyntaxThrowStatementFactory.CreateNotImplementedException()); return(SyntaxFactory.MethodDeclaration( SyntaxFactory.GenericName(SyntaxFactory.Identifier(nameof(Task))) .WithTypeArgumentList( SyntaxFactory.TypeArgumentList( SyntaxFactory.SingletonSeparatedList <TypeSyntax>( SyntaxFactory.GenericName( SyntaxFactory.Identifier("EndpointResult")) .WithTypeArgumentList( SyntaxFactory.TypeArgumentList( SyntaxFactory.SingletonSeparatedList <TypeSyntax>( SyntaxFactory.IdentifierName(resultTypeName))))))), SyntaxFactory.Identifier("ExecuteAsync")) .WithModifiers(SyntaxTokenListFactory.PublicKeyword()) .WithParameterList(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList <ParameterSyntax>(arguments))) .WithBody(codeBody)); }