@@ -33,7 +33,7 @@ public static CompilationResult GenerateAssembly(Compilation compilation)
3333 } ;
3434 }
3535
36- private static readonly ConcurrentDictionary < string , Tuple < List < SyntaxTree > , Assembly > > Assemblies = new ( ) ;
36+ private static readonly ConcurrentDictionary < string , Assembly > Assemblies = new ( ) ;
3737
3838 private static readonly string [ ] DependencyAssemblies = new [ ]
3939 {
@@ -55,33 +55,21 @@ public static CompilationResult GenerateAssembly(Compilation compilation)
5555 public static Assembly GetAssembly ( string name )
5656 {
5757 Assemblies . TryGetValue ( name , out var assembly ) ;
58- return assembly . Item2 ;
59- }
60-
61- public static Assembly Generate ( string name , string pattern , Generator generatorPrototype = null )
62- {
63- ( _ , var assembly ) = GenerateVerbose ( name , pattern , generatorPrototype ) ;
64- return assembly ;
58+ return assembly ;
6559 }
6660
67- public static ( List < SyntaxTree > , Assembly ) GenerateVerbose ( string name , string pattern , Generator generatorPrototype = null )
68- {
69- if ( Assemblies . TryGetValue ( name , out var assembly ) ) { return ( assembly . Item1 , assembly . Item2 ) ; }
61+ public static Assembly Generate ( string name , string pattern , Generator generatorPrototype = null )
62+ {
63+ if ( Assemblies . ContainsKey ( name ) ) { return Assemblies [ name ] ; }
7064
7165 var files = Glob . ExpandNames ( pattern ) . OrderByDescending ( f => f ) ;
7266
73- return GenerateFilesVerbose ( name , files , generatorPrototype ) ;
67+ return GenerateFiles ( name , files , generatorPrototype ) ;
7468 }
7569
76- public static Assembly GenerateFiles ( string name , IEnumerable < string > files , Generator generatorPrototype = null )
77- {
78- ( _ , var assembly ) = GenerateFilesVerbose ( name , files , generatorPrototype ) ;
79- return assembly ;
80- }
81-
82- public static ( List < SyntaxTree > , Assembly ) GenerateFilesVerbose ( string name , IEnumerable < string > files , Generator generatorPrototype = null )
83- {
84- if ( Assemblies . TryGetValue ( name , out var assembly ) ) { return ( assembly . Item1 , assembly . Item2 ) ; }
70+ public static Assembly GenerateFiles ( string name , IEnumerable < string > files , Generator generatorPrototype = null )
71+ {
72+ if ( Assemblies . ContainsKey ( name ) ) { return Assemblies [ name ] ; }
8573
8674 generatorPrototype ??= new Generator
8775 {
@@ -125,6 +113,7 @@ public static (List<SyntaxTree>, Assembly) GenerateFilesVerbose(string name, IEn
125113 UniqueTypeNamesAcrossNamespaces = generatorPrototype . UniqueTypeNamesAcrossNamespaces ,
126114 CreateGeneratedCodeAttributeVersion = generatorPrototype . CreateGeneratedCodeAttributeVersion ,
127115 NetCoreSpecificCode = generatorPrototype . NetCoreSpecificCode ,
116+ EnableNullableReferenceAttributes = generatorPrototype . EnableNullableReferenceAttributes ,
128117 NamingScheme = generatorPrototype . NamingScheme
129118 } ;
130119
@@ -135,40 +124,28 @@ public static (List<SyntaxTree>, Assembly) GenerateFilesVerbose(string name, IEn
135124
136125 gen . Generate ( files ) ;
137126
138- return CompileFilesVerbose ( name , output . Files ) ;
127+ return CompileFiles ( name , output . Files ) ;
139128 }
140129
141- public static Assembly CompileFiles ( string name , IEnumerable < string > files )
142- {
143- ( _ , var assembly ) = CompileFilesVerbose ( name , files ) ;
144- return assembly ;
145- }
146-
147- public static ( List < SyntaxTree > , Assembly ) CompileFilesVerbose ( string name , IEnumerable < string > files )
148- {
149- return CompileVerbose ( name , files . Select ( f => File . ReadAllText ( f ) ) . ToArray ( ) ) ;
130+ public static Assembly CompileFiles ( string name , IEnumerable < string > files )
131+ {
132+ return Compile ( name , files . Select ( f => File . ReadAllText ( f ) ) . ToArray ( ) ) ;
150133 }
151134
152135 private static readonly LanguageVersion MaxLanguageVersion = Enum
153136 . GetValues ( typeof ( LanguageVersion ) )
154137 . Cast < LanguageVersion > ( )
155138 . Max ( ) ;
156139
157- public static Assembly Compile ( string name , params string [ ] contents )
140+ public static Assembly Compile ( string name , params string [ ] contents )
158141 {
159- ( _ , var assembly ) = CompileVerbose ( name , contents ) ;
160- return assembly ;
161- }
162-
163- public static ( List < SyntaxTree > , Assembly ) CompileVerbose ( string name , params string [ ] contents )
164- {
165142 var trustedAssembliesPaths = ( ( string ) AppContext . GetData ( "TRUSTED_PLATFORM_ASSEMBLIES" ) ) . Split ( Path . PathSeparator ) ;
166143 var references = trustedAssembliesPaths
167144 . Where ( p => DependencyAssemblies . Contains ( Path . GetFileNameWithoutExtension ( p ) ) )
168145 . Select ( p => MetadataReference . CreateFromFile ( p ) )
169146 . ToList ( ) ;
170147 var options = new CSharpParseOptions ( kind : SourceCodeKind . Regular , languageVersion : MaxLanguageVersion ) ;
171- var syntaxTrees = contents . Select ( c => CSharpSyntaxTree . ParseText ( c , options ) ) . ToList ( ) ;
148+ var syntaxTrees = contents . Select ( c => CSharpSyntaxTree . ParseText ( c , options ) ) ;
172149 var compilation = CSharpCompilation . Create ( name , syntaxTrees )
173150 . AddReferences ( references )
174151 . WithOptions ( new CSharpCompilationOptions ( OutputKind . DynamicallyLinkedLibrary ) ) ;
@@ -179,9 +156,9 @@ public static (List<SyntaxTree>, Assembly) CompileVerbose(string name, params st
179156 Assert . True ( result . Result . Success ) ;
180157 Assert . NotNull ( result . Assembly ) ;
181158
182- Assemblies [ name ] = Tuple . Create ( syntaxTrees , result . Assembly ) ;
159+ Assemblies [ name ] = result . Assembly ;
183160
184- return ( syntaxTrees , result . Assembly ) ;
161+ return result . Assembly ;
185162 }
186163 }
187164}
0 commit comments