private static ConversionOperatorDeclarationSyntax GenerateConversionDeclarationWorker( IMethodSymbol method, CodeGenerationDestination destination, Workspace workspace, CodeGenerationOptions options, ParseOptions parseOptions) { var hasNoBody = !options.GenerateMethodBodies || method.IsExtern; var reusableSyntax = GetReuseableSyntaxNodeForSymbol <ConversionOperatorDeclarationSyntax>(method, options); if (reusableSyntax != null) { return(reusableSyntax); } var operatorToken = SyntaxFactory.Token(SyntaxFacts.GetOperatorKind(method.MetadataName)); var keyword = method.MetadataName == WellKnownMemberNames.ImplicitConversionName ? SyntaxFactory.Token(SyntaxKind.ImplicitKeyword) : SyntaxFactory.Token(SyntaxKind.ExplicitKeyword); var declaration = SyntaxFactory.ConversionOperatorDeclaration( attributeLists: AttributeGenerator.GenerateAttributeLists(method.GetAttributes(), options), modifiers: GenerateModifiers(method), implicitOrExplicitKeyword: keyword, operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword), type: method.ReturnType.GenerateTypeSyntax(), parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, isExplicit: false, options: options), body: hasNoBody ? null : StatementGenerator.GenerateBlock(method), semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken()); declaration = UseExpressionBodyIfDesired(workspace, declaration, parseOptions); return(declaration); }
private static OperatorDeclarationSyntax GenerateOperatorDeclarationWorker( IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options) { var hasNoBody = !options.GenerateMethodBodies || method.IsExtern; var operatorSyntaxKind = SyntaxFacts.GetOperatorKind(method.MetadataName); if (operatorSyntaxKind == SyntaxKind.None) { throw new ArgumentException(string.Format(WorkspacesResources.Cannot_generate_code_for_unsupported_operator_0, method.Name), nameof(method)); } var operatorToken = SyntaxFactory.Token(operatorSyntaxKind); return(SyntaxFactory.OperatorDeclaration( attributeLists: AttributeGenerator.GenerateAttributeLists(method.GetAttributes(), options), modifiers: GenerateModifiers(method), returnType: method.ReturnType.GenerateTypeSyntax(), operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword), operatorToken: operatorToken, parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, isExplicit: false, options: options), body: hasNoBody ? null : StatementGenerator.GenerateBlock(method), semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken())); }