public static async Task <Document> RefactorAsync( Document document, ReturnStatementSyntax returnStatement, ITypeSymbol typeSymbol, CancellationToken cancellationToken = default(CancellationToken)) { ExpressionSyntax expression = CSharpFactory.DefaultValue(typeSymbol); ReturnStatementSyntax newReturnStatement = returnStatement.WithExpression(expression); return(await document.ReplaceNodeAsync(returnStatement, newReturnStatement, cancellationToken).ConfigureAwait(false)); }
private static ParameterSyntax GetNewParameter( ParameterSyntax parameter, ITypeSymbol typeSymbol) { ExpressionSyntax value = CSharpFactory.DefaultValue( 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))); } }