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.Specialized;
40 using System.Reflection;
41 using System.Web.Configuration;
42 using System.Web.Hosting;
43 using System.Web.Util;
45 namespace System.Web.Compilation {
47 public abstract class BuildProvider {
49 ArrayList ref_assemblies;
51 ICollection vpath_deps;
53 protected BuildProvider()
55 ref_assemblies = new ArrayList ();
58 internal void SetVirtualPath (VirtualPath virtualPath)
60 virtual_path = virtualPath.Absolute;
63 internal virtual void GenerateCode ()
67 public virtual void GenerateCode (AssemblyBuilder assemblyBuilder)
71 public virtual string GetCustomString (CompilerResults results)
76 protected CompilerType GetDefaultCompilerType ()
78 CompilationSection config;
79 config = (CompilationSection) WebConfigurationManager.GetSection ("system.web/compilation");
80 return BuildManager.GetDefaultCompilerTypeForLanguage (config.DefaultLanguage, config);
83 protected CompilerType GetDefaultCompilerTypeForLanguage (string language)
85 return BuildManager.GetDefaultCompilerTypeForLanguage (language, null);
88 public virtual Type GetGeneratedType (CompilerResults results)
93 public virtual BuildProviderResultFlags GetResultFlags (CompilerResults results)
95 return BuildProviderResultFlags.Default;
98 protected TextReader OpenReader ()
100 return OpenReader (VirtualPath);
103 protected TextReader OpenReader (string virtualPath)
105 Stream st = OpenStream (virtualPath);
106 return new StreamReader (st, WebEncoding.FileEncoding);
109 protected Stream OpenStream ()
111 return OpenStream (VirtualPath);
114 protected Stream OpenStream (string virtualPath)
116 // MS also throws a NullReferenceException here when not hosted.
117 return VirtualPathProvider.OpenFile (virtualPath);
120 public virtual CompilerType CodeCompilerType {
121 get { return null; } // Documented to return null
124 protected ICollection ReferencedAssemblies {
125 get { return ref_assemblies; }
128 protected internal string VirtualPath {
129 get { return virtual_path; }
132 public virtual ICollection VirtualPathDependencies {
134 if (vpath_deps == null)
135 vpath_deps = new OneNullCollection ();
141 internal virtual CodeCompileUnit CodeUnit {
146 class OneNullCollection : ICollection {
151 public bool IsSynchronized {
152 get { return false; }
155 public object SyncRoot {
159 public void CopyTo (Array array, int index)
162 throw new ArgumentNullException ();
165 throw new ArgumentOutOfRangeException ();
168 throw new ArgumentException ();
170 int length = array.Length;
171 if (index >= length || index > length - 1)
172 throw new ArgumentException ();
174 array.SetValue (null, index);
177 public IEnumerator GetEnumerator ()