private static LambdaExpressionSyntax UpdateWorker( SemanticModel semanticModel, LambdaExpressionSyntax originalDeclaration, LambdaExpressionSyntax currentDeclaration) { var expressionBody = UseExpressionBodyForLambdaHelpers.GetBodyAsExpression(currentDeclaration); return(expressionBody == null ? WithExpressionBody(currentDeclaration, originalDeclaration.GetLanguageVersion()) : WithBlockBody(semanticModel, originalDeclaration, currentDeclaration, expressionBody)); }
private static LambdaExpressionSyntax WithExpressionBody(LambdaExpressionSyntax declaration, LanguageVersion languageVersion) { if (!UseExpressionBodyForLambdaHelpers.TryConvertToExpressionBody(declaration, languageVersion, ExpressionBodyPreference.WhenPossible, out var expressionBody)) { return(declaration); } var updatedDecl = declaration.WithBody(expressionBody); // If there will only be whitespace between the arrow and the body, then replace that // with a single space so that the lambda doesn't have superfluous newlines in it. if (declaration.ArrowToken.TrailingTrivia.All(t => t.IsWhitespaceOrEndOfLine()) && expressionBody.GetLeadingTrivia().All(t => t.IsWhitespaceOrEndOfLine())) { updatedDecl = updatedDecl.WithArrowToken(updatedDecl.ArrowToken.WithTrailingTrivia(SyntaxFactory.ElasticSpace)); } return(updatedDecl); }