2 // System.Web.Compilation.BuildProvider
5 // Chris Toshok (toshok@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // (C) 2006 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.CodeDom.Compiler;
37 using System.Collections;
38 using System.Collections.Generic;
39 using System.Collections.Specialized;
41 using System.Reflection;
42 using System.Web.Configuration;
43 using System.Web.Hosting;
44 using System.Web.Util;
46 namespace System.Web.Compilation {
48 public abstract class BuildProvider {
50 ArrayList ref_assemblies;
52 ICollection vpath_deps;
53 CompilationSection compilationSection;
55 CompilationSection CompilationConfig {
57 if (compilationSection == null)
58 compilationSection = WebConfigurationManager.GetSection ("system.web/compilation") as CompilationSection;
59 return compilationSection;
63 internal virtual string LanguageName {
64 get { return CompilationConfig.DefaultLanguage; }
67 protected BuildProvider()
69 ref_assemblies = new ArrayList ();
72 internal void SetVirtualPath (VirtualPath virtualPath)
74 virtual_path = virtualPath.Absolute;
77 internal virtual void GenerateCode ()
81 internal virtual List <string> ExtractDependencies ()
86 public virtual void GenerateCode (AssemblyBuilder assemblyBuilder)
90 public virtual string GetCustomString (CompilerResults results)
95 protected CompilerType GetDefaultCompilerType ()
97 return BuildManager.GetDefaultCompilerTypeForLanguage (CompilationConfig.DefaultLanguage, CompilationConfig);
100 protected CompilerType GetDefaultCompilerTypeForLanguage (string language)
102 return BuildManager.GetDefaultCompilerTypeForLanguage (language, null);
105 public virtual Type GetGeneratedType (CompilerResults results)
110 public virtual BuildProviderResultFlags GetResultFlags (CompilerResults results)
112 return BuildProviderResultFlags.Default;
115 protected TextReader OpenReader ()
117 return OpenReader (VirtualPath);
120 protected TextReader OpenReader (string virtualPath)
122 Stream st = OpenStream (virtualPath);
123 return new StreamReader (st, WebEncoding.FileEncoding);
126 protected Stream OpenStream ()
128 return OpenStream (VirtualPath);
131 protected Stream OpenStream (string virtualPath)
133 // MS also throws a NullReferenceException here when not hosted.
134 return VirtualPathProvider.OpenFile (virtualPath);
137 public virtual CompilerType CodeCompilerType {
138 get { return null; } // Documented to return null
141 protected ICollection ReferencedAssemblies {
142 get { return ref_assemblies; }
145 protected internal string VirtualPath {
146 get { return virtual_path; }
149 public virtual ICollection VirtualPathDependencies {
151 if (vpath_deps == null)
152 vpath_deps = new OneNullCollection ();
158 internal virtual CodeCompileUnit CodeUnit {
163 class OneNullCollection : ICollection {
168 public bool IsSynchronized {
169 get { return false; }
172 public object SyncRoot {
176 public void CopyTo (Array array, int index)
179 throw new ArgumentNullException ();
182 throw new ArgumentOutOfRangeException ();
185 throw new ArgumentException ();
187 int length = array.Length;
188 if (index >= length || index > length - 1)
189 throw new ArgumentException ();
191 array.SetValue (null, index);
194 public IEnumerator GetEnumerator ()