@@ -109,60 +109,37 @@ public static Assembly GenerateFiles(string name, IEnumerable<string> files, Gen
109109
110110 public static Assembly CompileFiles ( string name , IEnumerable < string > files )
111111 {
112- var trustedAssembliesPaths = ( ( string ) AppContext . GetData ( "TRUSTED_PLATFORM_ASSEMBLIES" ) ) . Split ( Path . PathSeparator ) ;
113- var references = trustedAssembliesPaths
114- . Where ( p => DependencyAssemblies . Contains ( Path . GetFileNameWithoutExtension ( p ) ) )
115- . Select ( p => MetadataReference . CreateFromFile ( p ) )
116- . ToList ( ) ;
117- var syntaxTrees = files . Select ( f => CSharpSyntaxTree . ParseText ( File . ReadAllText ( f ) ) ) . ToList ( ) ;
118- var compilation = CSharpCompilation . Create ( name , syntaxTrees )
119- . AddReferences ( references )
120- . WithOptions ( new CSharpCompilationOptions ( OutputKind . DynamicallyLinkedLibrary ) ) ;
121- var result = Compiler . GenerateAssembly ( compilation ) ;
122-
123- Assert . True ( result . Result . Success ) ;
124- var errors = result . Result . Diagnostics . Where ( d => d . Severity == DiagnosticSeverity . Error ) ;
125- Assert . False ( errors . Any ( ) , string . Join ( "\n " , errors . Select ( e => e . GetMessage ( ) ) ) ) ;
126- var warnings = result . Result . Diagnostics . Where ( d => d . Severity == DiagnosticSeverity . Warning ) ;
127- Assert . False ( warnings . Any ( ) , string . Join ( "\n " , errors . Select ( w => w . GetMessage ( ) ) ) ) ;
128- Assert . NotNull ( result . Assembly ) ;
129-
130- Assemblies [ name ] = result . Assembly ;
131-
132- return result . Assembly ;
112+ return Compile ( name , files . Select ( f => File . ReadAllText ( f ) ) . ToArray ( ) ) ;
133113 }
134114
135115 private static readonly LanguageVersion MaxLanguageVersion = Enum
136116 . GetValues ( typeof ( LanguageVersion ) )
137117 . Cast < LanguageVersion > ( )
138118 . Max ( ) ;
139119
140- public static Assembly Compile ( string name , string contents , Generator generator )
120+ public static Assembly Compile ( string name , params string [ ] contents )
141121 {
142122 var trustedAssembliesPaths = ( ( string ) AppContext . GetData ( "TRUSTED_PLATFORM_ASSEMBLIES" ) ) . Split ( Path . PathSeparator ) ;
143123 var references = trustedAssembliesPaths
144124 . Where ( p => DependencyAssemblies . Contains ( Path . GetFileNameWithoutExtension ( p ) ) )
145125 . Select ( p => MetadataReference . CreateFromFile ( p ) )
146126 . ToList ( ) ;
147-
148127 var options = new CSharpParseOptions ( kind : SourceCodeKind . Regular , languageVersion : MaxLanguageVersion ) ;
149-
150- // Return a syntax tree of our source code
151- var syntaxTree = CSharpSyntaxTree . ParseText ( contents , options ) ;
152-
153- var compilation = CSharpCompilation . Create ( name , new [ ] { syntaxTree } )
128+ var syntaxTrees = contents . Select ( c => CSharpSyntaxTree . ParseText ( c , options ) ) ;
129+ var compilation = CSharpCompilation . Create ( name , syntaxTrees )
154130 . AddReferences ( references )
155131 . WithOptions ( new CSharpCompilationOptions ( OutputKind . DynamicallyLinkedLibrary ) ) ;
156132 var result = Compiler . GenerateAssembly ( compilation ) ;
157133
158-
159134 Assert . True ( result . Result . Success ) ;
160135 var errors = result . Result . Diagnostics . Where ( d => d . Severity == DiagnosticSeverity . Error ) . ToList ( ) ;
161136 Assert . False ( errors . Any ( ) , string . Join ( "\n " , errors . Select ( e => e . GetMessage ( ) ) ) ) ;
162137 var warnings = result . Result . Diagnostics . Where ( d => d . Severity == DiagnosticSeverity . Warning ) . ToList ( ) ;
163138 Assert . False ( warnings . Any ( ) , string . Join ( "\n " , errors . Select ( w => w . GetMessage ( ) ) ) ) ;
164139 Assert . NotNull ( result . Assembly ) ;
165140
141+ Assemblies [ name ] = result . Assembly ;
142+
166143 return result . Assembly ;
167144 }
168145 }
0 commit comments