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 ConversionOperatorDeclarationSyntax CreateImplicitOperatorForActionResult(string className) { return(SyntaxFactory.ConversionOperatorDeclaration( SyntaxTokenFactory.ImplicitKeyword(), SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(nameof(ActionResult)))) .WithModifiers(SyntaxTokenListFactory.PublicStaticKeyword(true)) .WithOperatorKeyword(SyntaxTokenFactory.OperatorKeyword()) .AddParameterListParameters(SyntaxParameterFactory.Create(className, "x")) .WithExpressionBody(SyntaxFactory.ArrowExpressionClause( SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName("x"), SyntaxFactory.IdentifierName("result"))) .WithArrowToken(SyntaxTokenFactory.EqualsGreaterThan())) .WithSemicolonToken(SyntaxTokenFactory.Semicolon())); }
private static MethodDeclarationSyntax CreateTypeRequestWithSpecifiedResultFactoryMethodWithMessageAllowNull( string resultFactoryMethodName, string className, HttpStatusCode httpStatusCode, 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( SyntaxFactory.ObjectCreationExpression( SyntaxFactory.IdentifierName(className)) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( SyntaxFactory.InvocationExpression( SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName("ResultFactory"), SyntaxFactory.IdentifierName(resultFactoryMethodName))) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SeparatedList <ArgumentSyntax>( new SyntaxNodeOrToken[] { SyntaxFactory.Argument( SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName(nameof(HttpStatusCode)), SyntaxFactory.IdentifierName(httpStatusCode.ToString()))), SyntaxTokenFactory.Comma(), SyntaxFactory.Argument(SyntaxFactory.IdentifierName(parameterName)), }))))))))) .WithSemicolonToken(SyntaxTokenFactory.Semicolon())); }
private static MethodDeclarationSyntax CreateTypeRequestWithProblemDetailsWithMessage( string className, HttpStatusCode httpStatusCode, 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.PredefinedType(SyntaxTokenFactory.StringKeyword()))))) .WithExpressionBody( SyntaxFactory.ArrowExpressionClause( SyntaxFactory.ObjectCreationExpression( SyntaxFactory.IdentifierName(className)) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( SyntaxFactory.InvocationExpression( SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName("ResultFactory"), SyntaxFactory.IdentifierName("CreateContentResultWithProblemDetails"))) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SeparatedList <ArgumentSyntax>( new SyntaxNodeOrToken[] { SyntaxFactory.Argument( SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName(nameof(HttpStatusCode)), SyntaxFactory.IdentifierName(httpStatusCode.ToString()))), SyntaxTokenFactory.Comma(), SyntaxFactory.Argument(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())); }
private static ConversionOperatorDeclarationSyntax CreateImplicitOperator( string className, string typeName, HttpStatusCode httpStatusCode, 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; } var httpStatus = httpStatusCode.ToNormalizedString(); if (string.IsNullOrEmpty(typeName)) { typeName = "string"; } return(SyntaxFactory.ConversionOperatorDeclaration( SyntaxTokenFactory.ImplicitKeyword(), SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(className))) .WithModifiers(SyntaxTokenListFactory.PublicStaticKeyword(true)) .WithOperatorKeyword(SyntaxTokenFactory.OperatorKeyword()) .AddParameterListParameters(SyntaxParameterFactory.Create(typeName, "x", genericListTypeName)) .WithExpressionBody(SyntaxFactory.ArrowExpressionClause( SyntaxFactory.InvocationExpression(SyntaxFactory.IdentifierName(SyntaxFactory.Identifier(httpStatus))) .AddArgumentListArguments(SyntaxArgumentFactory.Create("x"))) .WithArrowToken(SyntaxTokenFactory.EqualsGreaterThan())) .WithSemicolonToken(SyntaxTokenFactory.Semicolon())); }
private static MethodDeclarationSyntax CreateStatusCodeResult( string className, HttpStatusCode httpStatusCode) { return(SyntaxFactory.MethodDeclaration(SyntaxFactory.IdentifierName(className), SyntaxFactory.Identifier(httpStatusCode.ToNormalizedString())) .WithModifiers(SyntaxTokenListFactory.PublicStaticKeyword()) .WithExpressionBody( SyntaxFactory.ArrowExpressionClause( SyntaxFactory.ObjectCreationExpression(SyntaxFactory.IdentifierName(className)) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( SyntaxFactory.ObjectCreationExpression(SyntaxFactory.IdentifierName(nameof(StatusCodeResult))) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Argument( SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName(nameof(StatusCodes)), SyntaxFactory.IdentifierName($"Status{(int)httpStatusCode}{httpStatusCode}")))))))))))) .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))); }