33 using System ;
44 using System . Collections . Concurrent ;
55 using System . Collections . Generic ;
6+ using System . Collections . Immutable ;
67 using System . ComponentModel . DataAnnotations ;
78 using System . IO ;
89 using System . Linq ;
1819 using Microsoft . CodeAnalysis . CSharp ;
1920 using Microsoft . CodeAnalysis . Razor ;
2021 using Microsoft . JSInterop ;
21- using Try ;
2222
2323 public class CompilationService
2424 {
@@ -44,17 +44,18 @@ @using MudBlazor
4444
4545 // Creating the initial compilation + reading references is on the order of 250ms without caching
4646 // so making sure it doesn't happen for each run.
47- private static CSharpCompilation baseCompilation ;
48- private static CSharpParseOptions cSharpParseOptions ;
47+ private static CSharpCompilation _baseCompilation ;
48+ private static CSharpParseOptions _cSharpParseOptions ;
4949
5050 private readonly RazorProjectFileSystem fileSystem = new VirtualRazorProjectFileSystem ( ) ;
51- private readonly RazorConfiguration configuration = RazorConfiguration . Create (
51+ private readonly RazorConfiguration configuration = new (
5252 RazorLanguageVersion . Latest ,
53- configurationName : "Blazor" ,
54- extensions : Array . Empty < RazorExtension > ( ) ) ;
53+ ConfigurationName : "Blazor" ,
54+ Extensions : ImmutableArray < RazorExtension > . Empty ) ;
5555
5656 public static async Task InitAsync ( HttpClient httpClient )
5757 {
58+
5859 var basicReferenceAssemblyRoots = new [ ]
5960 {
6061 typeof ( Console ) . Assembly , // System.Console
@@ -89,7 +90,7 @@ public static async Task InitAsync(HttpClient httpClient)
8990 . Select ( a => a . Value )
9091 . ToList ( ) ;
9192
92- baseCompilation = CSharpCompilation . Create (
93+ _baseCompilation = CSharpCompilation . Create (
9394 DefaultRootNamespace ,
9495 Array . Empty < SyntaxTree > ( ) ,
9596 basicReferenceAssemblies ,
@@ -104,7 +105,7 @@ public static async Task InitAsync(HttpClient httpClient)
104105 new KeyValuePair < string , ReportDiagnostic > ( "CS1702" , ReportDiagnostic . Suppress ) ,
105106 } ) ) ;
106107
107- cSharpParseOptions = new CSharpParseOptions ( LanguageVersion . Preview ) ;
108+ _cSharpParseOptions = new CSharpParseOptions ( LanguageVersion . Preview ) ;
108109 }
109110
110111 public async Task < CompileToAssemblyResult > CompileToAssemblyAsync (
@@ -154,10 +155,10 @@ private static CompileToAssemblyResult CompileToAssembly(IReadOnlyList<CompileTo
154155 for ( var i = 0 ; i < cSharpResults . Count ; i ++ )
155156 {
156157 var cSharpResult = cSharpResults [ i ] ;
157- syntaxTrees [ i ] = CSharpSyntaxTree . ParseText ( cSharpResult . Code , cSharpParseOptions , cSharpResult . FilePath ) ;
158+ syntaxTrees [ i ] = CSharpSyntaxTree . ParseText ( cSharpResult . Code , _cSharpParseOptions , cSharpResult . FilePath ) ;
158159 }
159160
160- var finalCompilation = baseCompilation . AddSyntaxTrees ( syntaxTrees ) ;
161+ var finalCompilation = _baseCompilation . AddSyntaxTrees ( syntaxTrees ) ;
161162
162163 var compilationDiagnostics = finalCompilation . GetDiagnostics ( ) . Where ( d => d . Severity > DiagnosticSeverity . Info ) ;
163164
@@ -181,7 +182,7 @@ private static CompileToAssemblyResult CompileToAssembly(IReadOnlyList<CompileTo
181182 return result ;
182183 }
183184
184- private static RazorProjectItem CreateRazorProjectItem ( string fileName , string fileContent )
185+ private static VirtualProjectItem CreateRazorProjectItem ( string fileName , string fileContent )
185186 {
186187 var fullPath = WorkingDirectory + fileName ;
187188
@@ -249,12 +250,12 @@ private async Task<IReadOnlyList<CompileToCSharpResult>> CompileToCSharpAsync(
249250 var tempAssembly = CompileToAssembly ( declarations ) ;
250251 if ( tempAssembly . Diagnostics . Any ( d => d . Severity == DiagnosticSeverity . Error ) )
251252 {
252- return new [ ] { new CompileToCSharpResult { Diagnostics = tempAssembly . Diagnostics } } ;
253+ return [ new CompileToCSharpResult { Diagnostics = tempAssembly . Diagnostics } ] ;
253254 }
254255
255256 // Add the 'temp' compilation as a metadata reference
256- var references = new List < MetadataReference > ( baseCompilation . References ) { tempAssembly . Compilation . ToMetadataReference ( ) } ;
257- projectEngine = this . CreateRazorProjectEngine ( references ) ;
257+ var references = new List < MetadataReference > ( _baseCompilation . References ) { tempAssembly . Compilation . ToMetadataReference ( ) } ;
258+ projectEngine = CreateRazorProjectEngine ( references ) ;
258259
259260 await ( updateStatusFunc ? . Invoke ( "Preparing Project" ) ?? Task . CompletedTask ) ;
260261
@@ -287,7 +288,7 @@ private async Task<IReadOnlyList<CompileToCSharpResult>> CompileToCSharpAsync(
287288 }
288289
289290 private RazorProjectEngine CreateRazorProjectEngine ( IReadOnlyList < MetadataReference > references ) =>
290- RazorProjectEngine . Create ( this . configuration , this . fileSystem , b =>
291+ RazorProjectEngine . Create ( configuration , fileSystem , b =>
291292 {
292293 b . SetRootNamespace ( DefaultRootNamespace ) ;
293294 b . AddDefaultImports ( DefaultImports ) ;
0 commit comments