@@ -413,8 +413,43 @@ private void Generate(SyntaxTree? tree, Assembly? assembly, List<MetadataReferen
413413 }
414414 )
415415) . AddUsings ( oldUsing ) ;
416- //Should I make "NormalizeWhitespace" option??? TODO!
417- //.NormalizeWhitespace().AddUsings(oldUsing);
416+
417+ if ( _Options . KeepBraceOnTheSameLine )
418+ {
419+ //
420+ //
421+ //Overriding root works only once.
422+ //I'm not sure how to properly fix this...
423+ //Below is a very bad code...
424+ //
425+ //
426+ List < SyntaxToken > allBraces = trueRoot . NormalizeWhitespace ( ) . DescendantTokens ( ) . Where ( ( e ) => e . IsKind ( SyntaxKind . OpenBraceToken ) ) . ToList ( ) ;
427+ int i = 0 ;
428+ while ( i < allBraces . Count )
429+ {
430+ for ( int j = 0 ; j < allBraces . Count ; j ++ )
431+ {
432+ SyntaxToken _token = allBraces [ j ] . GetPreviousToken ( ) ;
433+ if ( _token . HasTrailingTrivia )
434+ {
435+ SyntaxTrivia _trivia = _token . TrailingTrivia . Where ( ( e ) => e . IsKind ( SyntaxKind . EndOfLineTrivia ) ) . FirstOrDefault ( ) ;
436+ if ( ! _trivia . IsKind ( SyntaxKind . None ) )
437+ {
438+ SyntaxToken _replacedToken = _token . ReplaceTrivia ( _trivia , SyntaxFactory . Space ) ;
439+ trueRoot = trueRoot . ReplaceToken ( _token , _replacedToken ) ;
440+ break ;
441+ }
442+ }
443+ }
444+ allBraces = trueRoot . DescendantTokens ( ) . Where ( ( e ) => e . IsKind ( SyntaxKind . OpenBraceToken ) ) . ToList ( ) ;
445+ i ++ ;
446+ }
447+
448+ }
449+
450+ if ( _Options . NormalizeWhitespace )
451+ trueRoot = trueRoot . NormalizeWhitespace ( ) ;
452+
418453
419454 if ( rtPath != null && rtPath != string . Empty )
420455 {
@@ -444,7 +479,6 @@ private void Generate(SyntaxTree? tree, Assembly? assembly, List<MetadataReferen
444479
445480 foreach ( UsingDirectiveSyntax oU in oldUsing )
446481 {
447-
448482 if ( File . Exists ( Path . Combine ( rtPath , oU . Name + ".dll" ) ) )
449483 references . Add ( MetadataReference . CreateFromFile ( Path . Combine ( rtPath , oU . Name + ".dll" ) ) ) ;
450484 }
0 commit comments