CompilerParameters.ReferencedAssemblies do not have a set accessor
[mono.git] / mcs / class / System.Web / System.Web.Compilation / CSCompiler.cs
1 //
2 // System.Web.Compilation.CSCompiler
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
8 //
9 using System;
10 using System.CodeDom;
11 using System.CodeDom.Compiler;
12 using System.Collections;
13 using System.Collections.Specialized;
14 using System.IO;
15 using System.Text;
16 using System.Reflection;
17 using Microsoft.CSharp;
18
19 namespace System.Web.Compilation
20 {
21         class CSCompiler
22         {
23                 static CodeDomProvider provider;
24                 static ICodeCompiler compiler;
25                 string filename;
26                 ArrayList assemblies;
27                 CompilerParameters options;
28
29                 static CSCompiler ()
30                 {
31                         provider = new CSharpCodeProvider ();
32                         compiler = provider.CreateCompiler ();
33                 }
34
35                 private CSCompiler (string filename, ArrayList assemblies)
36                 {
37                         this.filename = filename;
38                         this.assemblies = assemblies;
39                         options = new CompilerParameters ();
40                         if (assemblies != null) {
41                                 StringCollection coll = options.ReferencedAssemblies;
42                                 foreach (string str in assemblies)
43                                         coll.Add (str);
44                         }
45                 }
46
47                 public Assembly GetCompiledAssembly ()
48                 {
49                         CompilerResults results = compiler.CompileAssemblyFromFile (options, filename);
50                         if (results.NativeCompilerReturnValue != 0) {
51                                 StreamReader reader = new StreamReader (filename);
52                                 throw new CompilationException (filename, results.Errors, reader.ReadToEnd ());
53                         }
54
55                         return results.CompiledAssembly;
56                 }
57
58                 static public Assembly CompileCSFile (string file, ArrayList assemblies)
59                 {
60                         CSCompiler compiler = new CSCompiler (file, assemblies);
61                         return compiler.GetCompiledAssembly ();
62                 }
63
64                 static public CodeDomProvider Provider {
65                         get { return provider; }
66                 }
67
68                 static public ICodeCompiler Compiler {
69                         get { return compiler; }
70                 }
71         }
72 }
73