public static async Task <Document> RefactorAsync( Document document, ReturnStatementSyntax returnStatement, ITypeSymbol typeSymbol, ISymbol symbol, CancellationToken cancellationToken = default(CancellationToken)) { SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); ExpressionSyntax expression = SyntaxUtility.CreateDefaultValue(typeSymbol); root = root.ReplaceNode( returnStatement, returnStatement.WithExpression(expression)); return(document.WithSyntaxRoot(root)); }
private static VariableDeclaratorSyntax GetNewDeclarator( VariableDeclaratorSyntax declarator, TypeSyntax type, ITypeSymbol typeSymbol) { ExpressionSyntax value = SyntaxUtility.CreateDefaultValue(typeSymbol, type); EqualsValueClauseSyntax @default = EqualsValueClause(value); if (declarator.Initializer == null || declarator.Initializer.IsMissing) { return(declarator .WithIdentifier(declarator.Identifier.WithoutTrailingTrivia()) .WithInitializer(@default.WithTrailingTrivia(declarator.Identifier.TrailingTrivia))); } else { return(declarator .WithInitializer(@default.WithTriviaFrom(declarator.Initializer.EqualsToken))); } }
private static ParameterSyntax GetNewParameter( ParameterSyntax parameter, ITypeSymbol typeSymbol) { ExpressionSyntax value = SyntaxUtility.CreateDefaultValue( typeSymbol, parameter.Type.WithoutTrivia()); EqualsValueClauseSyntax @default = EqualsValueClause(value); if (parameter.Default == null || parameter.IsMissing) { return(parameter .WithIdentifier(parameter.Identifier.WithoutTrailingTrivia()) .WithDefault(@default.WithTrailingTrivia(parameter.Identifier.TrailingTrivia))); } else { return(parameter .WithDefault(@default.WithTriviaFrom(parameter.Default.EqualsToken))); } }