Skip to content

Commit

Permalink
Merge pull request #48231 from louis-z/issue-48133
Browse files Browse the repository at this point in the history
CSharpConvertAutoPropertyToFullProperty... handles init accessor
  • Loading branch information
CyrusNajmabadi authored Oct 2, 2020
2 parents 2e37d69 + ae519a8 commit e4c91a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,34 @@ public partial class ConvertAutoPropertyToFullPropertyTests : AbstractCSharpCode
protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspace workspace, TestParameters parameters)
=> new CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider();

[Fact, Trait(Traits.Feature, Traits.Features.ConvertAutoPropertyToFullProperty)]
public async Task SimpleAutoPropertyTest()
[Theory, Trait(Traits.Feature, Traits.Features.ConvertAutoPropertyToFullProperty)]
[InlineData("set"), InlineData("init")]
[WorkItem(48133, "https://github.com/dotnet/roslyn/issues/48133")]
public async Task SimpleAutoPropertyTest(string setter)
{
var text = @"
var text = $@"
class TestClass
{
public int G[||]oo { get; set; }
}
{{
public int G[||]oo {{ get; {setter}; }}
}}
";
var expected = @"
var expected = $@"
class TestClass
{
{{
private int goo;
public int Goo
{
{{
get
{
{{
return goo;
}
set
{
}}
{setter}
{{
goo = value;
}
}
}
}}
}}
}}
";
await TestInRegularAndScriptAsync(text, expected, options: DoNotPreferExpressionBodiedAccessors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ internal override (SyntaxNode newGetAccessor, SyntaxNode newSetAccessor) GetNewA
private static (AccessorDeclarationSyntax getAccessor, AccessorDeclarationSyntax setAccessor)
GetExistingAccessors(AccessorListSyntax accessorListSyntax)
=> (accessorListSyntax.Accessors.FirstOrDefault(a => a.IsKind(SyntaxKind.GetAccessorDeclaration)),
accessorListSyntax.Accessors.FirstOrDefault(a => a.IsKind(SyntaxKind.SetAccessorDeclaration)));
accessorListSyntax.Accessors.FirstOrDefault(a => a.IsKind(SyntaxKind.SetAccessorDeclaration) ||
a.IsKind(SyntaxKind.InitAccessorDeclaration)));

private static SyntaxNode GetUpdatedAccessor(DocumentOptionSet options,
SyntaxNode accessor, SyntaxNode statement)
Expand Down

0 comments on commit e4c91a3

Please sign in to comment.