@@ -42,7 +42,7 @@ internal static bool SupportsLanguageFeature(this Document document, CSharpLangu
42
42
43
43
internal static bool SupportsLanguageVersion ( this Document document , LanguageVersion languageVersion )
44
44
{
45
- return ( ( CSharpParseOptions ) document . Project . ParseOptions ) . LanguageVersion >= languageVersion ;
45
+ return ( ( CSharpParseOptions ? ) document . Project . ParseOptions ) ? . LanguageVersion >= languageVersion ;
46
46
}
47
47
48
48
internal static DefaultSyntaxOptions GetDefaultSyntaxOptions ( this Document document , DefaultSyntaxOptions options = DefaultSyntaxOptions . None )
@@ -83,7 +83,7 @@ internal static Task<Document> RemoveMemberAsync(
83
83
if ( member is null )
84
84
throw new ArgumentNullException ( nameof ( member ) ) ;
85
85
86
- SyntaxNode parent = member . Parent ;
86
+ SyntaxNode ? parent = member . Parent ;
87
87
88
88
switch ( parent ? . Kind ( ) )
89
89
{
@@ -162,7 +162,10 @@ public static async Task<Document> RemoveCommentsAsync(
162
162
if ( document is null )
163
163
throw new ArgumentNullException ( nameof ( document ) ) ;
164
164
165
- SyntaxNode root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
165
+ SyntaxNode ? root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
166
+
167
+ if ( root is null )
168
+ return document ;
166
169
167
170
SyntaxNode newRoot = SyntaxRefactorings . RemoveComments ( root , comments )
168
171
. WithFormatterAnnotation ( ) ;
@@ -186,7 +189,10 @@ public static async Task<Document> RemoveCommentsAsync(
186
189
if ( document is null )
187
190
throw new ArgumentNullException ( nameof ( document ) ) ;
188
191
189
- SyntaxNode root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
192
+ SyntaxNode ? root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
193
+
194
+ if ( root is null )
195
+ return document ;
190
196
191
197
SyntaxNode newRoot = SyntaxRefactorings . RemoveComments ( root , span , comments )
192
198
. WithFormatterAnnotation ( ) ;
@@ -208,7 +214,10 @@ public static async Task<Document> RemoveTriviaAsync(
208
214
if ( document is null )
209
215
throw new ArgumentNullException ( nameof ( document ) ) ;
210
216
211
- SyntaxNode root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
217
+ SyntaxNode ? root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
218
+
219
+ if ( root is null )
220
+ return document ;
212
221
213
222
SyntaxNode newRoot = SyntaxRefactorings . RemoveTrivia ( root , span ) ;
214
223
@@ -229,7 +238,10 @@ public static async Task<Document> RemovePreprocessorDirectivesAsync(
229
238
if ( document is null )
230
239
throw new ArgumentNullException ( nameof ( document ) ) ;
231
240
232
- SyntaxNode root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
241
+ SyntaxNode ? root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
242
+
243
+ if ( root is null )
244
+ return document ;
233
245
234
246
SourceText sourceText = await document . GetTextAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
235
247
@@ -254,7 +266,10 @@ public static async Task<Document> RemovePreprocessorDirectivesAsync(
254
266
if ( document is null )
255
267
throw new ArgumentNullException ( nameof ( document ) ) ;
256
268
257
- SyntaxNode root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
269
+ SyntaxNode ? root = await document . GetSyntaxRootAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
270
+
271
+ if ( root is null )
272
+ return document ;
258
273
259
274
SourceText sourceText = await document . GetTextAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
260
275
@@ -400,7 +415,7 @@ internal static Task<Document> RemoveSingleLineDocumentationComment(
400
415
DocumentationCommentTriviaSyntax documentationComment ,
401
416
CancellationToken cancellationToken = default )
402
417
{
403
- SyntaxNode node = documentationComment . ParentTrivia . Token . Parent ;
418
+ SyntaxNode node = documentationComment . ParentTrivia . Token . Parent ! ;
404
419
SyntaxNode newNode = SyntaxRefactorings . RemoveSingleLineDocumentationComment ( node , documentationComment ) ;
405
420
406
421
return document . ReplaceNodeAsync ( node , newNode , cancellationToken ) ;
0 commit comments