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 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())); }