2 // System.Web.Configuration.CompilerCollection
5 // Chris Toshok (toshok@ximian.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
31 #if NET_2_0 && CONFIGURATION_DEP
34 using System
.Collections
.Generic
;
35 using System
.Configuration
;
37 namespace System
.CodeDom
.Compiler
39 [ConfigurationCollection (typeof (Compiler
), AddItemName
= "compiler", CollectionType
= ConfigurationElementCollectionType
.BasicMap
)]
40 internal sealed class CompilerCollection
: ConfigurationElementCollection
43 static readonly string defaultCompilerVersion
= "3.5";
45 static readonly string defaultCompilerVersion
= "2.0";
47 static ConfigurationPropertyCollection properties
;
48 static List
<CompilerInfo
> compiler_infos
;
49 static Dictionary
<string, CompilerInfo
> compiler_languages
;
50 static Dictionary
<string, CompilerInfo
> compiler_extensions
;
52 static CompilerCollection ()
54 properties
= new ConfigurationPropertyCollection ();
55 compiler_infos
= new List
<CompilerInfo
> ();
56 compiler_languages
= new Dictionary
<string, CompilerInfo
> (16, StringComparer
.OrdinalIgnoreCase
);
57 compiler_extensions
= new Dictionary
<string, CompilerInfo
> (6, StringComparer
.OrdinalIgnoreCase
);
59 CompilerInfo compiler
= new CompilerInfo ();
60 compiler
.Languages
= "c#;cs;csharp";
61 compiler
.Extensions
= ".cs";
62 compiler
.TypeName
= "Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
63 compiler
.ProviderOptions
= new Dictionary
<string, string> (1);
64 compiler
.ProviderOptions
["CompilerVersion"] = defaultCompilerVersion
;
65 AddCompilerInfo (compiler
);
67 compiler
= new CompilerInfo ();
68 compiler
.Languages
= "vb;vbs;visualbasic;vbscript";
69 compiler
.Extensions
= ".vb";
70 compiler
.TypeName
= "Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
71 compiler
.ProviderOptions
= new Dictionary
<string, string> (1);
72 compiler
.ProviderOptions
["CompilerVersion"] = defaultCompilerVersion
;
73 AddCompilerInfo (compiler
);
75 compiler
= new CompilerInfo ();
76 compiler
.Languages
= "js;jscript;javascript";
77 compiler
.Extensions
= ".js";
78 compiler
.TypeName
= "Microsoft.JScript.JScriptCodeProvider, Microsoft.JScript, Version=8.0.1100.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
79 compiler
.ProviderOptions
= new Dictionary
<string, string> (1);
80 compiler
.ProviderOptions
["CompilerVersion"] = defaultCompilerVersion
;
81 AddCompilerInfo (compiler
);
83 compiler
= new CompilerInfo ();
84 compiler
.Languages
= "vj#;vjs;vjsharp";
85 compiler
.Extensions
= ".jsl;.java";
86 compiler
.TypeName
= "Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
87 compiler
.ProviderOptions
= new Dictionary
<string, string> (1);
88 compiler
.ProviderOptions
["CompilerVersion"] = defaultCompilerVersion
;
89 AddCompilerInfo (compiler
);
91 compiler
= new CompilerInfo ();
92 compiler
.Languages
= "c++;mc;cpp";
93 compiler
.Extensions
= ".h";
94 compiler
.TypeName
= "Microsoft.VisualC.CppCodeProvider, CppCodeProvider, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
95 compiler
.ProviderOptions
= new Dictionary
<string, string> (1);
96 compiler
.ProviderOptions
["CompilerVersion"] = defaultCompilerVersion
;
97 AddCompilerInfo (compiler
);
100 public CompilerCollection ()
104 static void AddCompilerInfo (CompilerInfo ci
)
107 compiler_infos
.Add (ci
);
109 string[] languages
= ci
.GetLanguages ();
110 if (languages
!= null)
111 foreach (string language
in languages
)
112 compiler_languages
[language
] = ci
;
114 string[] extensions
= ci
.GetExtensions ();
115 if (extensions
!= null)
116 foreach (string extension
in extensions
)
117 compiler_extensions
[extension
] = ci
;
120 static void AddCompilerInfo (Compiler compiler
)
122 CompilerInfo ci
= new CompilerInfo ();
123 ci
.Languages
= compiler
.Language
;
124 ci
.Extensions
= compiler
.Extension
;
125 ci
.TypeName
= compiler
.Type
;
126 ci
.ProviderOptions
= compiler
.ProviderOptionsDictionary
;
127 ci
.CompilerOptions
= compiler
.CompilerOptions
;
128 ci
.WarningLevel
= compiler
.WarningLevel
;
129 AddCompilerInfo (ci
);
132 protected override void BaseAdd (ConfigurationElement element
)
134 Compiler compiler
= element
as Compiler
;
135 if (compiler
!= null)
136 AddCompilerInfo (compiler
);
137 base.BaseAdd (element
);
140 protected override bool ThrowOnDuplicate
{
141 get { return false; }
144 protected override ConfigurationElement
CreateNewElement ()
146 return new Compiler ();
149 public CompilerInfo
GetCompilerInfoForLanguage (string language
)
151 if (compiler_languages
.Count
== 0)
155 if (compiler_languages
.TryGetValue (language
, out ci
))
161 public CompilerInfo
GetCompilerInfoForExtension (string extension
)
163 if (compiler_extensions
.Count
== 0)
167 if (compiler_extensions
.TryGetValue (extension
, out ci
))
173 public string GetLanguageFromExtension (string extension
)
175 CompilerInfo ci
= GetCompilerInfoForExtension (extension
);
178 string[] languages
= ci
.GetLanguages ();
179 if (languages
!= null && languages
.Length
> 0)
180 return languages
[0];
184 public Compiler
Get (int index
)
186 return (Compiler
) BaseGet (index
);
189 public Compiler
Get (string language
)
191 return (Compiler
) BaseGet (language
);
194 protected override object GetElementKey (ConfigurationElement element
)
196 return ((Compiler
)element
).Language
;
199 public string GetKey (int index
)
201 return (string)BaseGetKey (index
);
204 public string[ ] AllKeys
{
206 string[] keys
= new string[compiler_infos
.Count
];
207 for (int i
= 0; i
< Count
; i
++)
208 keys
[i
] = compiler_infos
[i
].Languages
;
213 public override ConfigurationElementCollectionType CollectionType
{
214 get { return ConfigurationElementCollectionType.BasicMap; }
217 protected override string ElementName
{
218 get { return "compiler"; }
221 protected override ConfigurationPropertyCollection Properties
{
222 get { return properties; }
225 public Compiler
this[int index
] {
226 get { return (Compiler) BaseGet (index); }
229 public new CompilerInfo
this[string language
] {
231 return GetCompilerInfoForLanguage (language
);
235 public CompilerInfo
[] CompilerInfos
{
237 return compiler_infos
.ToArray ();