@@ -54,13 +54,19 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
5454 continue ;
5555 }
5656
57- var node = root . FindNode ( diagnostic . Location . SourceSpan , findInsideTrivia : true ) as XmlElementSyntax ;
58- if ( node == null )
57+ var node = root . FindNode ( diagnostic . Location . SourceSpan , findInsideTrivia : true ) as XmlNodeSyntax ;
58+
59+ var xmlElementSyntax = node as XmlElementSyntax ;
60+
61+ if ( xmlElementSyntax != null )
5962 {
60- continue ;
63+ context . RegisterCodeFix ( CodeAction . Create ( DocumentationResources . SA1642SA1643CodeFix , token => GetTransformedDocumentAsync ( context . Document , root , xmlElementSyntax ) , equivalenceKey : nameof ( SA1642SA1643CodeFixProvider ) ) , diagnostic ) ;
64+ }
65+ else
66+ {
67+ var xmlEmptyElementSyntax = node as XmlEmptyElementSyntax ;
68+ context . RegisterCodeFix ( CodeAction . Create ( DocumentationResources . SA1642SA1643CodeFix , token => GetTransformedDocumentAsync ( context . Document , root , xmlEmptyElementSyntax ) , equivalenceKey : nameof ( SA1642SA1643CodeFixProvider ) ) , diagnostic ) ;
6169 }
62-
63- context . RegisterCodeFix ( CodeAction . Create ( DocumentationResources . SA1642SA1643CodeFix , token => GetTransformedDocumentAsync ( context . Document , root , node ) , equivalenceKey : nameof ( SA1642SA1643CodeFixProvider ) ) , diagnostic ) ;
6470 }
6571 }
6672
@@ -136,6 +142,30 @@ private static Task<Document> GetTransformedDocumentAsync(Document document, Syn
136142 return Task . FromResult ( newDocument ) ;
137143 }
138144
145+ private static Task < Document > GetTransformedDocumentAsync ( Document document , SyntaxNode root , XmlEmptyElementSyntax node )
146+ {
147+ var typeDeclaration = node . FirstAncestorOrSelf < BaseTypeDeclarationSyntax > ( ) ;
148+ var declarationSyntax = node . FirstAncestorOrSelf < BaseMethodDeclarationSyntax > ( ) ;
149+ bool isStruct = typeDeclaration . IsKind ( SyntaxKind . StructDeclaration ) ;
150+
151+ TypeParameterListSyntax typeParameterList ;
152+ ClassDeclarationSyntax classDeclaration = typeDeclaration as ClassDeclarationSyntax ;
153+ if ( classDeclaration != null )
154+ {
155+ typeParameterList = classDeclaration . TypeParameterList ;
156+ }
157+ else
158+ {
159+ typeParameterList = ( typeDeclaration as StructDeclarationSyntax ) ? . TypeParameterList ;
160+ }
161+
162+ var newRoot = root . ReplaceNode ( node , BuildSeeElement ( typeDeclaration . Identifier , typeParameterList ) ) ;
163+
164+ var newDocument = document . WithSyntaxRoot ( newRoot ) ;
165+
166+ return Task . FromResult ( newDocument ) ;
167+ }
168+
139169 private static SyntaxList < XmlNodeSyntax > RemoveMalformattedStandardText ( SyntaxList < XmlNodeSyntax > content , SyntaxToken identifier , string preText , string postText , ref string trailingString )
140170 {
141171 var regex = new Regex ( @"^\s*" + Regex . Escape ( preText ) + "[^ ]+" + Regex . Escape ( postText ) ) ;
@@ -208,6 +238,15 @@ private static SyntaxList<XmlNodeSyntax> RemoveMalformattedStandardText(SyntaxLi
208238 }
209239
210240 private static SyntaxList < XmlNodeSyntax > BuildStandardText ( SyntaxToken identifier , TypeParameterListSyntax typeParameters , string newLineText , string preText , string postText )
241+ {
242+ return XmlSyntaxFactory . List (
243+ XmlSyntaxFactory . NewLine ( newLineText ) ,
244+ XmlSyntaxFactory . Text ( preText ) ,
245+ BuildSeeElement ( identifier , typeParameters ) ,
246+ XmlSyntaxFactory . Text ( postText . EndsWith ( "." ) ? postText : ( postText + "." ) ) ) ;
247+ }
248+
249+ private static XmlEmptyElementSyntax BuildSeeElement ( SyntaxToken identifier , TypeParameterListSyntax typeParameters )
211250 {
212251 TypeSyntax identifierName ;
213252
@@ -221,11 +260,7 @@ private static SyntaxList<XmlNodeSyntax> BuildStandardText(SyntaxToken identifie
221260 identifierName = SyntaxFactory . GenericName ( identifier . WithoutTrivia ( ) , ParameterToArgumentListSyntax ( typeParameters ) ) ;
222261 }
223262
224- return XmlSyntaxFactory . List (
225- XmlSyntaxFactory . NewLine ( newLineText ) ,
226- XmlSyntaxFactory . Text ( preText ) ,
227- XmlSyntaxFactory . SeeElement ( SyntaxFactory . TypeCref ( identifierName ) ) ,
228- XmlSyntaxFactory . Text ( postText . EndsWith ( "." ) ? postText : ( postText + "." ) ) ) ;
263+ return XmlSyntaxFactory . SeeElement ( SyntaxFactory . TypeCref ( identifierName ) ) ;
229264 }
230265
231266 private static TypeArgumentListSyntax ParameterToArgumentListSyntax ( TypeParameterListSyntax typeParameters )
0 commit comments