@@ -17,8 +17,6 @@ namespace Microsoft.DotNet.GenAPI.SyntaxRewriter
17
17
/// </summary>
18
18
public class TypeDeclarationCSharpSyntaxRewriter : CSharpSyntaxRewriter
19
19
{
20
- private const string GlobalSystemObjectBaseTypeName = "global::System.Object" ;
21
-
22
20
private readonly bool _addPartialModifier ;
23
21
24
22
/// <summary>
@@ -64,43 +62,32 @@ public class TypeDeclarationCSharpSyntaxRewriter : CSharpSyntaxRewriter
64
62
65
63
private static T ? RemoveBaseType < T > ( T ? node , Func < BaseTypeSyntax , bool > selector ) where T : TypeDeclarationSyntax
66
64
{
67
- if ( node ? . BaseList == null )
65
+ if ( node == null )
68
66
{
69
67
return null ;
70
68
}
71
69
72
- BaseTypeSyntax ? baseType = node . BaseList . Types . FirstOrDefault ( selector ) ;
70
+ BaseTypeSyntax ? baseType = node . BaseList ? . Types . FirstOrDefault ( selector ) ;
73
71
if ( baseType == null )
74
72
{
75
73
// Base type not found
76
74
return node ;
77
75
}
78
- SyntaxTriviaList baseTypeTrailingTrivia = baseType . GetTrailingTrivia ( ) ;
79
- SeparatedSyntaxList < BaseTypeSyntax > baseTypes = node . BaseList . Types . Remove ( baseType ) ;
76
+
77
+ SeparatedSyntaxList < BaseTypeSyntax > baseTypes = node . BaseList ! . Types . Remove ( baseType ) ;
80
78
if ( baseTypes . Count == 0 )
81
79
{
82
- // After the baseType is removed, there is a remaining space that also needs removing
83
- SyntaxTriviaList identifierTrailingTrivia = node . Identifier . TrailingTrivia ;
84
- if ( identifierTrailingTrivia . Any ( ) && identifierTrailingTrivia . Last ( ) . IsKind ( SyntaxKind . WhitespaceTrivia ) )
85
- {
86
- identifierTrailingTrivia = identifierTrailingTrivia . RemoveAt ( identifierTrailingTrivia . Count - 1 ) ;
87
- identifierTrailingTrivia = identifierTrailingTrivia . AddRange ( baseTypeTrailingTrivia ) ; // Join what was after the removed baseType
88
- node = ( T ) node . WithIdentifier ( SyntaxFactory . Identifier ( node . Identifier . LeadingTrivia , node . Identifier . Text , identifierTrailingTrivia ) ) ;
89
- }
90
-
91
80
// No more base implementations, remove the base list entirely
92
81
// Make sure we update the identifier though to include the baselist trailing trivia (typically '\r\n')
93
82
// so the trailing opening brace gets put onto a new line.
94
83
return ( T ) node
95
84
. WithBaseList ( null )
96
- . WithTrailingTrivia ( node . GetTrailingTrivia ( ) ) ;
85
+ . WithTrailingTrivia ( node . BaseList . GetTrailingTrivia ( ) ) ;
97
86
}
98
87
else
99
88
{
100
89
// Remove the type but retain all remaining types and trivia
101
- return ( T ) node
102
- . WithBaseList ( node . BaseList . WithTypes ( baseTypes ) )
103
- . WithTrailingTrivia ( node . GetTrailingTrivia ( ) ) ;
90
+ return ( T ) node . WithBaseList ( node . BaseList ! . WithTypes ( baseTypes ) ) ;
104
91
}
105
92
}
106
93
@@ -111,7 +98,7 @@ public class TypeDeclarationCSharpSyntaxRewriter : CSharpSyntaxRewriter
111
98
return null ;
112
99
}
113
100
114
- node = RemoveBaseType ( node , GlobalSystemObjectBaseTypeName ) ;
101
+ node = RemoveBaseType ( node , "global::System.Object" ) ;
115
102
return _addPartialModifier ? AddPartialModifier ( node ) : node ;
116
103
}
117
104
0 commit comments