@@ -372,24 +372,31 @@ protected override async ValueTask VisitDirectiveLocationsAsync(GraphQLDirective
372
372
if ( Options . EachDirectiveLocationOnNewLine )
373
373
{
374
374
await context . WriteAsync ( " on" ) . ConfigureAwait ( false ) ;
375
- await context . WriteLineAsync ( ) . ConfigureAwait ( false ) ;
376
- for ( int i = 0 ; i < directiveLocations . Items . Count ; ++ i )
375
+ if ( directiveLocations . Items ? . Count > 0 ) // should always be true but may be negligently uninitialized
377
376
{
378
- await WriteIndentAsync ( context ) . ConfigureAwait ( false ) ;
379
- await context . WriteAsync ( "| " ) . ConfigureAwait ( false ) ;
380
- await context . WriteAsync ( GetDirectiveLocation ( directiveLocations . Items [ i ] ) ) . ConfigureAwait ( false ) ;
381
- if ( i < directiveLocations . Items . Count - 1 )
382
- await context . WriteLineAsync ( ) . ConfigureAwait ( false ) ;
377
+ await context . WriteLineAsync ( ) . ConfigureAwait ( false ) ;
378
+ for ( int i = 0 ; i < directiveLocations . Items . Count ; ++ i )
379
+ {
380
+ await WriteIndentAsync ( context ) . ConfigureAwait ( false ) ;
381
+ await context . WriteAsync ( "| " ) . ConfigureAwait ( false ) ;
382
+ await context . WriteAsync ( GetDirectiveLocation ( directiveLocations . Items [ i ] ) ) . ConfigureAwait ( false ) ;
383
+ if ( i < directiveLocations . Items . Count - 1 )
384
+ await context . WriteLineAsync ( ) . ConfigureAwait ( false ) ;
385
+ }
383
386
}
384
387
}
385
388
else
386
389
{
387
- await context . WriteAsync ( " on " ) . ConfigureAwait ( false ) ;
388
- for ( int i = 0 ; i < directiveLocations . Items . Count ; ++ i )
390
+ await context . WriteAsync ( " on" ) . ConfigureAwait ( false ) ;
391
+ if ( directiveLocations . Items ? . Count > 0 ) // should always be true but may be negligently uninitialized
389
392
{
390
- await context . WriteAsync ( GetDirectiveLocation ( directiveLocations . Items [ i ] ) ) . ConfigureAwait ( false ) ;
391
- if ( i < directiveLocations . Items . Count - 1 )
392
- await context . WriteAsync ( " | " ) . ConfigureAwait ( false ) ;
393
+ await context . WriteAsync ( " " ) . ConfigureAwait ( false ) ;
394
+ for ( int i = 0 ; i < directiveLocations . Items . Count ; ++ i )
395
+ {
396
+ await context . WriteAsync ( GetDirectiveLocation ( directiveLocations . Items [ i ] ) ) . ConfigureAwait ( false ) ;
397
+ if ( i < directiveLocations . Items . Count - 1 )
398
+ await context . WriteAsync ( " | " ) . ConfigureAwait ( false ) ;
399
+ }
393
400
}
394
401
}
395
402
}
0 commit comments