@@ -41,10 +41,10 @@ public static void GenerateStubs(ILogger logger, IEnumerable<string> referencesP
4141 references . Select ( tuple => tuple . Item1 ) ,
4242 new CSharpCompilationOptions ( OutputKind . ConsoleApplication , allowUnsafe : true ) ) ;
4343
44- var referenceStubTasks = references . Select ( @ref => ( Action ) ( ( ) => StubReference ( compilation , outputPath , @ref . Reference , @ref . Path ) ) ) ;
45- Parallel . Invoke (
46- new ParallelOptions { MaxDegreeOfParallelism = threads } ,
47- referenceStubTasks . ToArray ( ) ) ;
44+ Parallel . ForEach ( references , new ParallelOptions { MaxDegreeOfParallelism = threads } , @ref =>
45+ {
46+ StubReference ( logger , compilation , outputPath , @ref . Reference , @ref . Path ) ;
47+ } ) ;
4848
4949 stopWatch . Stop ( ) ;
5050 logger . Log ( Severity . Info , $ "Stub generation took { stopWatch . Elapsed } .") ;
@@ -59,25 +59,24 @@ private static IEnumerable<Action> GetResolvedReferenceTasks(IEnumerable<string>
5959 } ) ;
6060 }
6161
62- private static void StubReference ( CSharpCompilation compilation , string outputPath , MetadataReference reference , string path )
62+ private static void StubReference ( ILogger logger , CSharpCompilation compilation , string outputPath , MetadataReference reference , string path )
6363 {
64- if ( compilation . GetAssemblyOrModuleSymbol ( reference ) is IAssemblySymbol assembly )
65- {
66- var logger = new ConsoleLogger ( Verbosity . Info ) ;
67- using var fileStream = new FileStream ( FileUtils . NestPaths ( logger , outputPath , path . Replace ( ".dll" , ".cs" ) ) , FileMode . Create , FileAccess . Write ) ;
68- using var writer = new StreamWriter ( fileStream , new UTF8Encoding ( false ) ) ;
64+ if ( compilation . GetAssemblyOrModuleSymbol ( reference ) is not IAssemblySymbol assembly )
65+ return ;
66+
67+ using var fileStream = new FileStream ( FileUtils . NestPaths ( logger , outputPath , path . Replace ( ".dll" , ".cs" ) ) , FileMode . Create , FileAccess . Write ) ;
68+ using var writer = new StreamWriter ( fileStream , new UTF8Encoding ( false ) ) ;
6969
70- writer . WriteLine ( "// This file contains auto-generated code." ) ;
71- writer . WriteLine ( $ "// Generated from `{ assembly . Identity } `.") ;
70+ writer . WriteLine ( "// This file contains auto-generated code." ) ;
71+ writer . WriteLine ( $ "// Generated from `{ assembly . Identity } `.") ;
7272
73- var visitor = new StubVisitor ( assembly , writer ) ;
73+ var visitor = new StubVisitor ( assembly , writer ) ;
7474
75- visitor . StubAttributes ( assembly . GetAttributes ( ) , "assembly: " ) ;
75+ visitor . StubAttributes ( assembly . GetAttributes ( ) , "assembly: " ) ;
7676
77- foreach ( var module in assembly . Modules )
78- {
79- module . GlobalNamespace . Accept ( new StubVisitor ( assembly , writer ) ) ;
80- }
77+ foreach ( var module in assembly . Modules )
78+ {
79+ module . GlobalNamespace . Accept ( visitor ) ;
8180 }
8281 }
8382}
0 commit comments