@@ -123,7 +123,7 @@ private static Document FixContextIsNotStaticError(CodeFixContext context, Synta
123123 var propertyDeclaration = GetDeclarationSyntax < PropertyDeclarationSyntax > ( root , diagnosticSpan ) ;
124124 if ( propertyDeclaration is null ) return context . Document ;
125125
126- var newPropertyDeclaration = propertyDeclaration . AddModifiers ( SyntaxFactory . Token ( SyntaxKind . StaticKeyword ) ) ;
126+ var newPropertyDeclaration = FixRestrictivePropertyModifiers ( propertyDeclaration ) . AddModifiers ( SyntaxFactory . Token ( SyntaxKind . StaticKeyword ) ) ;
127127
128128 var newRoot = root . ReplaceNode ( propertyDeclaration , newPropertyDeclaration ) ;
129129 return context . Document . WithSyntaxRoot ( newRoot ) ;
@@ -134,20 +134,7 @@ private static Document FixContextIsTooRestricted(CodeFixContext context, Syntax
134134 var propertyDeclaration = GetDeclarationSyntax < PropertyDeclarationSyntax > ( root , diagnosticSpan ) ;
135135 if ( propertyDeclaration is null ) return context . Document ;
136136
137- var newModifiers = SyntaxFactory . TokenList ( ) ;
138- foreach ( var modifier in propertyDeclaration . Modifiers )
139- {
140- if ( modifier . IsKind ( SyntaxKind . PrivateKeyword ) || modifier . IsKind ( SyntaxKind . ProtectedKeyword ) )
141- {
142- newModifiers = newModifiers . Add ( SyntaxFactory . Token ( SyntaxKind . InternalKeyword ) ) ;
143- }
144- else
145- {
146- newModifiers = newModifiers . Add ( modifier ) ;
147- }
148- }
149-
150- var newPropertyDeclaration = propertyDeclaration . WithModifiers ( newModifiers ) ;
137+ var newPropertyDeclaration = FixRestrictivePropertyModifiers ( propertyDeclaration ) ;
151138
152139 var newRoot = root . ReplaceNode ( propertyDeclaration , newPropertyDeclaration ) ;
153140 return context . Document . WithSyntaxRoot ( newRoot ) ;
@@ -172,6 +159,24 @@ private static Document FixContextIsAFieldError(CodeFixContext context, SyntaxNo
172159 return GetFormattedDocument ( context , newRoot ) ;
173160 }
174161
162+ private static PropertyDeclarationSyntax FixRestrictivePropertyModifiers ( PropertyDeclarationSyntax propertyDeclaration )
163+ {
164+ var newModifiers = SyntaxFactory . TokenList ( ) ;
165+ foreach ( var modifier in propertyDeclaration . Modifiers )
166+ {
167+ if ( modifier . IsKind ( SyntaxKind . PrivateKeyword ) || modifier . IsKind ( SyntaxKind . ProtectedKeyword ) )
168+ {
169+ newModifiers = newModifiers . Add ( SyntaxFactory . Token ( SyntaxKind . InternalKeyword ) ) ;
170+ }
171+ else
172+ {
173+ newModifiers = newModifiers . Add ( modifier ) ;
174+ }
175+ }
176+
177+ return propertyDeclaration . WithModifiers ( newModifiers ) ;
178+ }
179+
175180 private static T GetDeclarationSyntax < T > ( SyntaxNode root , TextSpan diagnosticSpan ) where T : SyntaxNode =>
176181 root
177182 . FindToken ( diagnosticSpan . Start )
0 commit comments