@@ -84,7 +84,7 @@ public class CompilationGenerator
8484 /// <param name="progress">Optional handler of diagnostics provided by code generator.</param>
8585 /// <param name="cancellationToken">Cancellation token to interrupt async operations.</param>
8686 /// <returns>A <see cref="Task.CompletedTask"/>.</returns>
87- public async Task GenerateAsync ( IProgress < Diagnostic > progress , CancellationToken cancellationToken )
87+ public async Task GenerateAsync ( IProgress < Diagnostic > progress = null , CancellationToken cancellationToken = default )
8888 {
8989 Verify . Operation ( this . Compile != null , $ "{ nameof ( Compile ) } must be set first.") ;
9090 Verify . Operation ( this . ReferencePath != null , $ "{ nameof ( ReferencePath ) } must be set first.") ;
@@ -104,14 +104,13 @@ public async Task GenerateAsync(IProgress<Diagnostic> progress, CancellationToke
104104 {
105105 cancellationToken . ThrowIfCancellationRequested ( ) ;
106106
107- string sourceHash = Convert . ToBase64String ( hasher . ComputeHash ( Encoding . UTF8 . GetBytes ( inputSyntaxTree . FilePath ) ) , 0 , 6 ) . Replace ( Path . AltDirectorySeparatorChar , '-' ) . Replace ( Path . DirectorySeparatorChar , '-' ) ;
107+ string sourceHash = Convert . ToBase64String ( hasher . ComputeHash ( Encoding . UTF8 . GetBytes ( inputSyntaxTree . FilePath ) ) , 0 , 6 ) . Replace ( '/' , '-' ) ;
108108 Logger . Info ( $ "File \" { inputSyntaxTree . FilePath } \" hashed to { sourceHash } ") ;
109- string outputFilePath = Path . Combine ( this . IntermediateOutputDirectory , Path . GetFileNameWithoutExtension ( inputSyntaxTree . FilePath ) + FormattableString . Invariant ( $ ".{ sourceHash } .generated.cs") ) ;
110- var outputFile = new FileInfo ( outputFilePath ) ;
109+ string outputFilePath = Path . Combine ( this . IntermediateOutputDirectory , Path . GetFileNameWithoutExtension ( inputSyntaxTree . FilePath ) + $ ".{ sourceHash } .generated.cs") ;
111110
112111 // Code generation is relatively fast, but it's not free.
113112 // So skip files that haven't changed since we last generated them.
114- DateTime outputLastModified = outputFile . Exists ? outputFile . LastWriteTime : DateTime . MinValue ;
113+ DateTime outputLastModified = File . Exists ( outputFilePath ) ? File . GetLastWriteTime ( outputFilePath ) : DateTime . MinValue ;
115114 if ( File . GetLastWriteTime ( inputSyntaxTree . FilePath ) > outputLastModified || assembliesLastModified > outputLastModified )
116115 {
117116 int retriesLeft = 3 ;
@@ -127,7 +126,7 @@ public async Task GenerateAsync(IProgress<Diagnostic> progress, CancellationToke
127126 progress ,
128127 cancellationToken ) ;
129128 var outputText = await generatedSyntaxTree . GetTextAsync ( cancellationToken ) ;
130- using ( var outputFileStream = outputFile . OpenWrite ( ) )
129+ using ( var outputFileStream = File . OpenWrite ( outputFilePath ) )
131130 using ( var outputWriter = new StreamWriter ( outputFileStream ) )
132131 {
133132 outputText . Write ( outputWriter , cancellationToken ) ;
@@ -143,7 +142,7 @@ public async Task GenerateAsync(IProgress<Diagnostic> progress, CancellationToke
143142 bool anyTypesGenerated = root . DescendantNodes ( ) . OfType < TypeDeclarationSyntax > ( ) . Any ( ) ;
144143 if ( ! anyTypesGenerated )
145144 {
146- this . emptyGeneratedFiles . Add ( outputFile . FullName ) ;
145+ this . emptyGeneratedFiles . Add ( outputFilePath ) ;
147146 }
148147 }
149148 break ;
@@ -163,7 +162,7 @@ public async Task GenerateAsync(IProgress<Diagnostic> progress, CancellationToke
163162 while ( true ) ;
164163 }
165164
166- this . generatedFiles . Add ( outputFile . FullName ) ;
165+ this . generatedFiles . Add ( outputFilePath ) ;
167166 }
168167 }
169168
@@ -233,7 +232,10 @@ private static void ReportError(IProgress<Diagnostic> progress, string id, Synta
233232
234233 var location = inputSyntaxTree != null ? Location . Create ( inputSyntaxTree , TextSpan . FromBounds ( 0 , 0 ) ) : Location . None ;
235234
236- var messageArgs = new object [ ] { ex } ;
235+ var messageArgs = new object [ ]
236+ {
237+ ex ,
238+ } ;
237239
238240 var reportDiagnostic = Diagnostic . Create ( descriptor , location , messageArgs ) ;
239241
0 commit comments