From 284e42de80585e3ba71827603ad996a3c78545b8 Mon Sep 17 00:00:00 2001 From: Louis Zanella Date: Thu, 1 Oct 2020 19:50:58 -0400 Subject: [PATCH 1/2] CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider supports init accessor --- .../ConvertAutoPropertyToFullPropertyTests.cs | 34 ++++++++++--------- ...tyToFullPropertyCodeRefactoringProvider.cs | 3 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs b/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs index fef7b81537f66..59ff4b50198d5 100644 --- a/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs +++ b/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs @@ -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); } diff --git a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs index 67a1ae07b00ed..f85ac24e03d50 100644 --- a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs @@ -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) From ae519a8376505c1f2830eb6b81a7684dacbb6efd Mon Sep 17 00:00:00 2001 From: Louis Zanella Date: Fri, 2 Oct 2020 07:33:43 -0400 Subject: [PATCH 2/2] Update src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs Co-authored-by: CyrusNajmabadi --- .../ConvertAutoPropertyToFullPropertyTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs b/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs index 59ff4b50198d5..35763d7b379d7 100644 --- a/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs +++ b/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests.cs @@ -23,8 +23,8 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa => new CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider(); [Theory, Trait(Traits.Feature, Traits.Features.ConvertAutoPropertyToFullProperty)] - [InlineData("set")] - [InlineData("init"), WorkItem(48133, "https://github.com/dotnet/roslyn/issues/48133")] + [InlineData("set"), InlineData("init")] + [WorkItem(48133, "https://github.com/dotnet/roslyn/issues/48133")] public async Task SimpleAutoPropertyTest(string setter) { var text = $@"