private static MethodDeclarationSyntax CreateTypeRequestWithMessageAllowNull( string className, HttpStatusCode httpStatusCode, string typeRequestName, string parameterName = "message") { return(SyntaxFactory.MethodDeclaration( SyntaxFactory.IdentifierName(className), SyntaxFactory.Identifier(httpStatusCode.ToNormalizedString())) .WithModifiers(SyntaxTokenListFactory.PublicStaticKeyword()) .WithParameterList( SyntaxFactory.ParameterList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Parameter(SyntaxFactory.Identifier(parameterName)) .WithType(SyntaxFactory.NullableType(SyntaxFactory.PredefinedType(SyntaxTokenFactory.StringKeyword()))) .WithDefault( SyntaxFactory.EqualsValueClause( SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)))))) .WithExpressionBody( SyntaxFactory.ArrowExpressionClause( SyntaxObjectCreationExpressionFactory.Create(className) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( SyntaxObjectCreationExpressionFactory.Create(typeRequestName) .WithArgumentList( SyntaxArgumentListFactory.CreateWithOneItem(parameterName)))))))) .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))); }
private static MethodDeclarationSyntax CreateTypeRequestWithObject( string className, HttpStatusCode httpStatusCode, string typeRequestName, string parameterName = "message") { return(SyntaxFactory.MethodDeclaration( SyntaxFactory.IdentifierName(className), SyntaxFactory.Identifier(httpStatusCode.ToNormalizedString())) .WithModifiers(SyntaxTokenListFactory.PublicStaticKeyword()) .WithParameterList( SyntaxFactory.ParameterList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Parameter(SyntaxFactory.Identifier(parameterName)) .WithType(SyntaxFactory.NullableType(SyntaxFactory.PredefinedType(SyntaxTokenFactory.StringKeyword()))) .WithDefault( SyntaxFactory.EqualsValueClause( SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)))))) .WithExpressionBody( SyntaxFactory.ArrowExpressionClause( SyntaxObjectCreationExpressionFactory.Create(className) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( SyntaxObjectCreationExpressionFactory.Create(typeRequestName) .WithInitializer( SyntaxFactory.InitializerExpression( SyntaxKind.ObjectInitializerExpression, SyntaxFactory.SeparatedList <ExpressionSyntax>( new SyntaxNodeOrToken[] { SyntaxFactory.AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName("StatusCode"), SyntaxFactory.CastExpression( SyntaxFactory.PredefinedType( SyntaxFactory.Token(SyntaxKind.IntKeyword)), SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName(nameof(HttpStatusCode)), SyntaxFactory.IdentifierName(httpStatusCode.ToNormalizedString())))), SyntaxTokenFactory.Comma(), SyntaxFactory.AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName("Content"), SyntaxFactory.IdentifierName(parameterName)), }))))))))) .WithSemicolonToken(SyntaxTokenFactory.Semicolon())); }
private static MethodDeclarationSyntax CreateTypeRequest( string className, HttpStatusCode httpStatusCode, string typeRequestName) { return(SyntaxFactory.MethodDeclaration( SyntaxFactory.IdentifierName(className), SyntaxFactory.Identifier(httpStatusCode.ToNormalizedString())) .WithModifiers(SyntaxTokenListFactory.PublicStaticKeyword()) .WithExpressionBody( SyntaxFactory.ArrowExpressionClause( SyntaxObjectCreationExpressionFactory.Create(className) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( SyntaxFactory.ObjectCreationExpression( SyntaxFactory.IdentifierName(typeRequestName)) .WithArgumentList(SyntaxFactory.ArgumentList()))))))) .WithSemicolonToken(SyntaxTokenFactory.Semicolon())); }
private static MethodDeclarationSyntax CreateTypeRequestObjectResult( string className, string methodName, string parameterTypeName, string parameterName = "response", bool asGenericList = false, bool asGenericPagination = false) { string?genericListTypeName = null; if (asGenericList) { genericListTypeName = Microsoft.OpenApi.Models.NameConstants.List; } else if (asGenericPagination) { genericListTypeName = Microsoft.OpenApi.Models.NameConstants.Pagination; } if (string.IsNullOrEmpty(parameterTypeName)) { parameterTypeName = "string"; } return(SyntaxFactory.MethodDeclaration( SyntaxFactory.IdentifierName(className), SyntaxFactory.Identifier(methodName)) .WithModifiers(SyntaxTokenListFactory.PublicStaticKeyword()) .WithParameterList(SyntaxParameterListFactory.CreateWithOneItem(parameterTypeName, parameterName, genericListTypeName)) .WithExpressionBody( SyntaxFactory.ArrowExpressionClause( SyntaxObjectCreationExpressionFactory.Create(className) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( SyntaxObjectCreationExpressionFactory.Create(methodName + nameof(ObjectResult)) .WithArgumentList(SyntaxArgumentListFactory.CreateWithOneItem(parameterName)))))))) .WithSemicolonToken(SyntaxTokenFactory.Semicolon())); }