@@ -157,18 +157,22 @@ public async Task<SyntaxList<MemberDeclarationSyntax>> CreateVbStaticFieldsAsync
157157 var declarations = new List < FieldDeclarationSyntax > ( ) ;
158158
159159 var fieldInfo = GetFields ( ) ;
160- var newNames = fieldInfo . ToDictionary ( f => f . OriginalVariableName , f =>
160+ var newNames = fieldInfo . ToDictionary ( f => f . PrefixedOriginalVariableName , f =>
161161 NameGenerator . CS . GetUniqueVariableNameInScope ( semanticModel , generatedNames , typeNode , f . FieldName )
162162 ) ;
163163 foreach ( var field in fieldInfo ) {
164164 var decl = ( field . Initializer != null )
165- ? CommonConversions . CreateVariableDeclarationAndAssignment ( newNames [ field . OriginalVariableName ] , field . Initializer , field . Type )
166- : SyntaxFactory . VariableDeclaration ( field . Type , SyntaxFactory . SingletonSeparatedList ( SyntaxFactory . VariableDeclarator ( newNames [ field . OriginalVariableName ] ) ) ) ;
165+ ? CommonConversions . CreateVariableDeclarationAndAssignment ( newNames [ field . PrefixedOriginalVariableName ] , field . Initializer , field . Type )
166+ : SyntaxFactory . VariableDeclaration ( field . Type , SyntaxFactory . SingletonSeparatedList ( SyntaxFactory . VariableDeclarator ( newNames [ field . PrefixedOriginalVariableName ] ) ) ) ;
167167 var modifiers = new List < SyntaxToken > { CS . SyntaxFactory . Token ( SyntaxKind . PrivateKeyword ) } ;
168168 if ( field . IsStatic || namedTypeSymbol . IsModuleType ( ) ) {
169169 modifiers . Add ( CS . SyntaxFactory . Token ( SyntaxKind . StaticKeyword ) ) ;
170170 }
171- declarations . Add ( CS . SyntaxFactory . FieldDeclaration ( CS . SyntaxFactory . List < AttributeListSyntax > ( ) , CS . SyntaxFactory . TokenList ( modifiers ) , decl ) ) ;
171+ var fieldDecl = CS . SyntaxFactory . FieldDeclaration ( CS . SyntaxFactory . List < AttributeListSyntax > ( ) , CS . SyntaxFactory . TokenList ( modifiers ) , decl ) ;
172+ if ( field . OriginalParentAccessorKind != MethodKind . Ordinary ) {
173+ fieldDecl = fieldDecl . WithParentPropertyAccessorKind ( field . OriginalParentAccessorKind ) ;
174+ }
175+ declarations . Add ( fieldDecl ) ;
172176 }
173177
174178 var statementsWithUpdatedIds = ReplaceNames ( declarations . Concat ( csNodes ) , newNames ) ;
@@ -185,11 +189,23 @@ public static IEnumerable<T> ReplaceNames<T>(IEnumerable<T> csNodes, Dictionary<
185189 public static T ReplaceNames < T > ( T csNode , Dictionary < string , string > newNames ) where T : SyntaxNode
186190 {
187191 return csNode . ReplaceNodes ( csNode . DescendantNodesAndSelf ( ) . OfType < IdentifierNameSyntax > ( ) , ( _ , idns ) => {
188- if ( newNames . TryGetValue ( idns . Identifier . ValueText , out var newName ) ) {
192+ if ( TryGetValue ( newNames , idns , out var newName ) ) {
189193 return idns . WithoutAnnotations ( AdditionalLocalAnnotation ) . WithIdentifier ( CS . SyntaxFactory . Identifier ( newName ) ) ;
190194 }
191195 return idns ;
192196 } ) ;
197+
198+ static bool TryGetValue ( Dictionary < string , string > newNames , IdentifierNameSyntax idns , out string newName )
199+ {
200+ var ann = idns . GetAnnotations ( AnnotationConstants . ParentPropertyAccessorKindAnnotation ) . FirstOrDefault ( ) ;
201+ var key = GetPrefixedName ( ann ? . Data , idns . Identifier . ValueText ) ;
202+ return newNames . TryGetValue ( key , out newName ) ;
203+ }
204+ }
205+
206+ internal static string GetPrefixedName ( string prefix , string name )
207+ {
208+ return string . IsNullOrEmpty ( prefix ) ? name : $ "<{ prefix } >.{ name } ";
193209 }
194210
195211 public IEnumerable < StatementSyntax > ConvertExit ( VBasic . SyntaxKind vbBlockKeywordKind )
0 commit comments