@@ -27,39 +27,29 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
27
27
{
28
28
context . RegisterCodeFix (
29
29
CodeAction . Create ( "Fix mismatched route parameter and argument optionality" ,
30
- cancellationToken => FixMismatchedParameterOptionality ( context , cancellationToken ) ,
30
+ cancellationToken => FixMismatchedParameterOptionality ( diagnostic , context . Document , cancellationToken ) ,
31
31
equivalenceKey : DiagnosticDescriptors . DetectMismatchedParameterOptionality . Id ) ,
32
32
diagnostic ) ;
33
33
}
34
34
35
35
return Task . CompletedTask ;
36
36
}
37
37
38
- private static async Task < Document > FixMismatchedParameterOptionality ( CodeFixContext context , CancellationToken cancellationToken )
38
+ private static async Task < Document > FixMismatchedParameterOptionality ( Diagnostic diagnostic , Document document , CancellationToken cancellationToken )
39
39
{
40
- DocumentEditor editor = await DocumentEditor . CreateAsync ( context . Document , cancellationToken ) ;
41
- var root = await context . Document . GetSyntaxRootAsync ( context . CancellationToken ) . ConfigureAwait ( false ) ;
40
+ DocumentEditor editor = await DocumentEditor . CreateAsync ( document , cancellationToken ) ;
41
+ var root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
42
42
43
43
if ( root == null )
44
44
{
45
- return context . Document ;
46
- }
47
-
48
- var diagnostic = context . Diagnostics . SingleOrDefault ( ) ;
49
-
50
- if ( diagnostic == null )
51
- {
52
- return context . Document ;
45
+ return document ;
53
46
}
54
47
55
48
var param = root . FindNode ( diagnostic . Location . SourceSpan ) ;
56
- if ( param != null && param is ParameterSyntax parameterSyntax )
49
+ if ( param is ParameterSyntax { Type : { } parameterType } parameterSyntax )
57
50
{
58
- if ( parameterSyntax . Type != null )
59
- {
60
- var newParam = parameterSyntax . WithType ( SyntaxFactory . NullableType ( parameterSyntax . Type ) ) ;
61
- editor . ReplaceNode ( parameterSyntax , newParam ) ;
62
- }
51
+ var newParam = parameterSyntax . WithType ( SyntaxFactory . NullableType ( parameterType ) ) ;
52
+ editor . ReplaceNode ( parameterSyntax , newParam ) ;
63
53
}
64
54
65
55
return editor . GetChangedDocument ( ) ;
0 commit comments