|
7 | 7 | using Microsoft.CodeAnalysis; |
8 | 8 | using Microsoft.CodeAnalysis.CSharp; |
9 | 9 | using Microsoft.CodeAnalysis.CSharp.Syntax; |
| 10 | +using Microsoft.CodeAnalysis.FindSymbols; |
10 | 11 | using SyntaxFactory = Microsoft.CodeAnalysis.CSharp.SyntaxFactory; |
11 | 12 | using VBSyntax = Microsoft.CodeAnalysis.VisualBasic.Syntax; |
12 | 13 | using VBasic = Microsoft.CodeAnalysis.VisualBasic; |
@@ -449,15 +450,17 @@ public override CSharpSyntaxNode VisitPropertyStatement(VBSyntax.PropertyStateme |
449 | 450 |
|
450 | 451 | AccessorListSyntax accessors = null; |
451 | 452 | if (!hasBody) { |
452 | | - var accessorList = new List<AccessorDeclarationSyntax>(); |
453 | | - |
454 | | - if (!isWriteOnly) { |
455 | | - accessorList.Add(SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(SemicolonToken)); |
| 453 | + var getAccessor = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(SemicolonToken); |
| 454 | + var setAccessor = SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).WithSemicolonToken(SemicolonToken); |
| 455 | + if (isWriteOnly) { |
| 456 | + getAccessor = getAccessor.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)); |
456 | 457 | } |
457 | | - if (!isReadonly) { |
458 | | - accessorList.Add(SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).WithSemicolonToken(SemicolonToken)); |
| 458 | + if (isReadonly) { |
| 459 | + setAccessor = setAccessor.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)); |
459 | 460 | } |
460 | | - accessors = SyntaxFactory.AccessorList(SyntaxFactory.List(accessorList)); |
| 461 | + // In VB, there's a backing field which can always be read and written to even on ReadOnly/WriteOnly properties. |
| 462 | + // Our conversion will rewrite usages of that field to use the property accessors which therefore must exist and be private at minimum. |
| 463 | + accessors = SyntaxFactory.AccessorList(SyntaxFactory.List(new[] {getAccessor, setAccessor})); |
461 | 464 | } else { |
462 | 465 | accessors = SyntaxFactory.AccessorList( |
463 | 466 | SyntaxFactory.List( |
|
0 commit comments