提交 8cfbae24 编写于 作者: C CyrusNajmabadi

Preserve trailing trivia in 'Replace Proprty with Methods'

上级 423afea1
......@@ -280,6 +280,23 @@ public async Task TestComputedProp()
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)]
public async Task TestComputedPropWithTrailingTrivia()
{
await TestAsync(
@"class C
{
int [||]Prop => 1; // Comment
}",
@"class C
{
private int GetProp()
{
return 1; // Comment
}
}", compareTokens: false);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)]
public async Task TestAbstractProperty()
{
......
......@@ -63,7 +63,8 @@ public override SyntaxNode GetPropertyDeclaration(SyntaxToken token)
private List<SyntaxNode> ConvertPropertyToMembers(
SyntaxGenerator generator,
IPropertySymbol property, PropertyDeclarationSyntax propertyDeclaration,
IPropertySymbol property,
PropertyDeclarationSyntax propertyDeclaration,
IFieldSymbol propertyBackingField,
string desiredGetMethodName,
string desiredSetMethodName,
......@@ -134,7 +135,9 @@ public override SyntaxNode GetPropertyDeclaration(SyntaxToken token)
if (propertyDeclaration.ExpressionBody != null)
{
statements.Add(generator.ReturnStatement(propertyDeclaration.ExpressionBody.Expression));
var returnStatement = SyntaxFactory.ReturnStatement(propertyDeclaration.ExpressionBody.Expression)
.WithSemicolonToken(propertyDeclaration.SemicolonToken);
statements.Add(returnStatement);
}
else
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册