AssemblyBuilder.Units property is no longer used
[mono.git] / mcs / class / System.Web / System.Web.Compilation / BuildProvider.cs
1 //
2 // System.Web.Compilation.BuildProvider
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //
8 // (C) 2006 Novell, Inc (http://www.novell.com)
9 //
10
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 #if NET_2_0
33
34 using System;
35 using System.CodeDom;
36 using System.CodeDom.Compiler;
37 using System.Collections;
38 using System.Collections.Generic;
39 using System.Collections.Specialized;
40 using System.IO;
41 using System.Reflection;
42 using System.Web.Configuration;
43 using System.Web.Hosting;
44 using System.Web.Util;
45
46 namespace System.Web.Compilation {
47
48         public abstract class BuildProvider {
49                 string virtual_path;
50                 ArrayList ref_assemblies;
51                 
52                 ICollection vpath_deps;
53                 CompilationSection compilationSection;
54                 
55                 CompilationSection CompilationConfig {
56                         get {
57                                 if (compilationSection == null)
58                                         compilationSection = WebConfigurationManager.GetSection ("system.web/compilation") as CompilationSection;
59                                 return compilationSection;
60                         }
61                 }
62                 
63                 internal virtual string LanguageName {
64                         get { return CompilationConfig.DefaultLanguage; }
65                 }
66                 
67                 protected BuildProvider()
68                 {
69                         ref_assemblies = new ArrayList ();
70                 }
71
72                 internal void SetVirtualPath (VirtualPath virtualPath)
73                 {
74                         virtual_path = virtualPath.Absolute;
75                 }
76
77                 internal virtual void GenerateCode ()
78                 {
79                 }
80
81                 internal virtual List <string> ExtractDependencies ()
82                 {
83                         return null;
84                 }
85                 
86                 public virtual void GenerateCode (AssemblyBuilder assemblyBuilder)
87                 {
88                 }
89
90                 public virtual string GetCustomString (CompilerResults results)
91                 {
92                         return null;
93                 }
94
95                 protected CompilerType GetDefaultCompilerType ()
96                 {
97                         return BuildManager.GetDefaultCompilerTypeForLanguage (CompilationConfig.DefaultLanguage, CompilationConfig);
98                 }
99                 
100                 protected CompilerType GetDefaultCompilerTypeForLanguage (string language)
101                 {
102                         return BuildManager.GetDefaultCompilerTypeForLanguage (language, null);
103                 }
104
105                 public virtual Type GetGeneratedType (CompilerResults results)
106                 {
107                         return null;
108                 }
109
110                 public virtual BuildProviderResultFlags GetResultFlags (CompilerResults results)
111                 {
112                         return BuildProviderResultFlags.Default;
113                 }
114
115                 protected TextReader OpenReader ()
116                 {
117                         return OpenReader (VirtualPath);
118                 }
119
120                 protected TextReader OpenReader (string virtualPath)
121                 {
122                         Stream st = OpenStream (virtualPath);
123                         return new StreamReader (st, WebEncoding.FileEncoding);
124                 }
125
126                 protected Stream OpenStream ()
127                 {
128                         return OpenStream (VirtualPath);
129                 }
130
131                 protected Stream OpenStream (string virtualPath)
132                 {
133                         // MS also throws a NullReferenceException here when not hosted.
134                         return VirtualPathProvider.OpenFile (virtualPath);
135                 }
136                 
137                 public virtual CompilerType CodeCompilerType {
138                         get { return null; } // Documented to return null
139                 }
140
141                 protected ICollection ReferencedAssemblies {
142                         get { return ref_assemblies; }
143                 }
144
145                 protected internal string VirtualPath {
146                         get { return virtual_path; }
147                 }
148
149                 public virtual ICollection VirtualPathDependencies {
150                         get {
151                                 if (vpath_deps == null)
152                                         vpath_deps = new OneNullCollection ();
153
154                                 return vpath_deps;
155                         }
156                 }
157
158                 internal virtual CodeCompileUnit CodeUnit {
159                         get { return null; }
160                 }
161         }
162
163         class OneNullCollection : ICollection {
164                 public int Count {
165                         get { return 1; }
166                 }
167
168                 public bool IsSynchronized {
169                         get { return false; }
170                 }
171
172                 public object SyncRoot {
173                         get { return this; }
174                 }
175
176                 public void CopyTo (Array array, int index)
177                 {
178                         if (array == null)
179                                 throw new ArgumentNullException ();
180
181                         if (index < 0)
182                                 throw new ArgumentOutOfRangeException ();
183
184                         if (array.Rank > 1)
185                                 throw new ArgumentException ();
186
187                         int length = array.Length;
188                         if (index >= length || index > length - 1)
189                                 throw new ArgumentException ();
190
191                         array.SetValue (null, index);
192                 }
193
194                 public IEnumerator GetEnumerator ()
195                 {
196                         yield return null;
197                 }
198         }
199 }
200 #endif
201