2006-01-09 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / Compiler.cs
1 //
2 // System.Web.Configuration.CompilerCollection
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32 #if CONFIGURATION_2_0
33 using System;
34 using System.CodeDom.Compiler;
35 using System.ComponentModel;
36 using System.Configuration;
37
38 namespace System.Web.Configuration
39 {
40         public sealed class Compiler : ConfigurationElement
41         {
42                 static ConfigurationProperty compilerOptionsProp;
43                 static ConfigurationProperty extensionProp;
44                 static ConfigurationProperty languageProp;
45                 static ConfigurationProperty typeProp;
46                 static ConfigurationProperty warningLevelProp;
47
48                 static ConfigurationPropertyCollection properties;
49
50                 static Compiler ()
51                 {
52                         compilerOptionsProp = new ConfigurationProperty("compilerOptions", typeof (string), "");
53                         extensionProp = new ConfigurationProperty("extension", typeof (string), "");
54                         languageProp = new ConfigurationProperty("language", typeof (string), "", ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
55                         typeProp = new ConfigurationProperty("type", typeof (string), "", ConfigurationPropertyOptions.IsRequired);
56                         warningLevelProp = new ConfigurationProperty("warningLevel", typeof (int), 0,
57                                                                      TypeDescriptor.GetConverter (typeof (int)),
58                                                                      new IntegerValidator (0, 4),
59                                                                      ConfigurationPropertyOptions.None);
60
61                         properties = new ConfigurationPropertyCollection ();
62                         properties.Add (compilerOptionsProp);
63                         properties.Add (extensionProp);
64                         properties.Add (languageProp);
65                         properties.Add (typeProp);
66                         properties.Add (warningLevelProp);
67                 }
68
69                 internal Compiler ()
70                 {
71                 }
72
73                 public Compiler (string compilerOptions, string extension, string language, string type, int warningLevel)
74                 {
75                         this.CompilerOptions = compilerOptions;
76                         this.Extension = extension;
77                         this.Language = language;
78                         this.Type = type;
79                         this.WarningLevel = warningLevel;
80                 }
81
82                 [ConfigurationProperty ("compilerOptions", DefaultValue = "")]
83                 public string CompilerOptions {
84                         get { return (string) base[compilerOptionsProp]; }
85                         internal set { base[compilerOptionsProp] = value; }
86                 }
87
88                 [ConfigurationProperty ("extension", DefaultValue = "")]
89                 public string Extension {
90                         get { return (string) base[extensionProp]; }
91                         internal set { base[extensionProp] = value; }
92                 }
93
94                 [ConfigurationProperty ("language", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
95                 public string Language {
96                         get { return (string) base[languageProp]; }
97                         internal set { base[languageProp] = value; }
98                 }
99
100                 [ConfigurationProperty ("type", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired)]
101                 public string Type {
102                         get { return (string) base[typeProp]; }
103                         internal set { base[typeProp] = value; }
104                 }
105
106                 [IntegerValidator (MinValue = 0, MaxValue = 4)]
107                 [ConfigurationProperty ("warningLevel", DefaultValue = "0")]
108                 public int WarningLevel {
109                         get { return (int) base[warningLevelProp]; }
110                         internal set { base[warningLevelProp] = value; }
111                 }
112
113                 protected override ConfigurationPropertyCollection Properties {
114                         get { return properties; }
115                 }
116
117 #region CompatabilityCode
118                 [MonoTODO ("we shouldn't need this")]
119                 CodeDomProvider provider;
120                 internal CodeDomProvider Provider {
121                         get { 
122                                 if (provider == null) {
123                                         Type t = System.Type.GetType (this.Type);
124                                         provider = Activator.CreateInstance (t) as CodeDomProvider;
125                                 }
126                                 return provider;
127                         }
128                         set {
129                                 provider = value;
130                         }
131                 }
132 #endregion
133         }
134 }
135 #endif
136 #endif