Reimplementation of the CodeDomConfigurationHandler class as a ConfigurationSection...
authorMarek Habersack <grendel@twistedcode.net>
Thu, 16 Nov 2006 00:13:33 +0000 (00:13 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Thu, 16 Nov 2006 00:13:33 +0000 (00:13 -0000)
svn path=/trunk/mcs/; revision=67961

mcs/class/System/System.CodeDom.Compiler/ChangeLog
mcs/class/System/System.CodeDom.Compiler/CodeDomConfigurationHandler.cs
mcs/class/System/System.CodeDom.Compiler/CodeDomProvider.cs
mcs/class/System/System.CodeDom.Compiler/Compiler.cs [new file with mode: 0644]
mcs/class/System/System.CodeDom.Compiler/CompilerCollection.cs [new file with mode: 0644]
mcs/class/System/System.dll.sources

index 9869d61d5d1206db6820805136347811e46bc5b6..47f4208fbb7e82158e45ef69b9f403ae62e4e7e9 100644 (file)
@@ -1,3 +1,17 @@
+2006-11-16  Marek Habersack  <grendello@gmail.com>
+
+       * Compiler.cs: ConfigurationElement to handle the <compiler>
+       sub-element of the <system.codedom> section
+
+       * CodeDomConfigurationHandler.cs: Reimplemented as a
+       ConfigurationSection. Made the class internal.
+
+       * CompilerCollection.cs: Collection of Compiler and CompilerInfo
+       objects.
+
+       * CodeDomProvider.cs: Changes to use the new
+       CodeDomConfigurationHandler class.
+
 2006-11-07  Marek Habersack  <grendello@gmail.com>
 
        * CompilerInfo.cs: Implement the CreateDefaultCompilerParameters API.
index 2dac7f096becee2964811367a035c28955fb342d..34f77c72f5390f57171a37ce0cb248477861d25a 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
+#if NET_2_0 && CONFIGURATION_DEP
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.Configuration;
 using System.IO;
-#if XML_DEP
-using System.Xml;
-#endif
 
 namespace System.CodeDom.Compiler
 {
-#if XML_DEP
-       class CodeDomConfigurationHandler : IConfigurationSectionHandler
+       internal sealed class CodeDomConfigurationHandler: ConfigurationSection
        {
-               public object Create (object parent, object context, XmlNode section)
-               {
-                       return new CompilationConfigurationHandler ().Create (parent, context, section);
-               }
-       }
+               static ConfigurationPropertyCollection properties;
+               static ConfigurationProperty compilersProp;
+               static CompilerCollection default_compilers;
 
-       class CompilationConfigurationHandler : IConfigurationSectionHandler
-       {
-               public object Create (object parent, object context, XmlNode section)
+               static CodeDomConfigurationHandler ()
                {
-                       CompilationConfiguration config = new CompilationConfiguration (parent);
-
-                       config.TempDirectory = AttValue ("tempDirectory", section, true);
-                       config.DefaultLanguage = AttValue ("defaultLanguage", section);
-                       if (config.DefaultLanguage == null)
-                               config.DefaultLanguage = "c#";
-
-                       config.Debug = AttBoolValue ("debug", section, false);
-                       config.Batch = AttBoolValue ("batch", section, false);
-                       config.Explicit = AttBoolValue ("explicit", section, true);
-                       config.Strict = AttBoolValue ("strict", section, false);
-                       config.BatchTimeout = AttUIntValue ("batchTimeout", section, 0);
-                       config.MaxBatchSize = AttUIntValue ("maxBatchSize", section, 0);
-                       config.MaxBatchFileSize = AttUIntValue ("maxBatchFileSize", section, 0);
-                       config.NumRecompilesBeforeAppRestart =
-                                       AttUIntValue ("numRecompilesBeforeAppRestart", section, 15);
-
-                       if (section.Attributes != null && section.Attributes.Count != 0)
-                               ThrowException ("Unrecognized attribute.", section);
-
-                       XmlNodeList authNodes = section.ChildNodes;
-                       foreach (XmlNode child in authNodes) {
-                               XmlNodeType ntype = child.NodeType;
-                               if (ntype != XmlNodeType.Element)
-                                       continue;
-                               
-                               if (child.Name == "compilers") {
-                                       ReadCompilers (child.ChildNodes, config);
-                                       continue;
-                               }
-
-                               ThrowException ("Unexpected element", child);
-                       }
-
-                       return config;
+                       default_compilers = new CompilerCollection ();
+                       compilersProp = new ConfigurationProperty ("compilers", typeof (CompilerCollection), default_compilers);
+                       properties = new ConfigurationPropertyCollection ();
+                       properties.Add (compilersProp);
                }
 
-               static void ReadCompilers (XmlNodeList nodes, CompilationConfiguration config)
+               public CodeDomConfigurationHandler ()
                {
-                       foreach (XmlNode child in nodes) {
-                               XmlNodeType ntype = child.NodeType;
-                               if (ntype != XmlNodeType.Element)
-                                       continue;
-
-                               if (child.Name != "compiler")
-                                       ThrowException ("Unexpected element", child);
-
-                               CompilerInfo compiler = new CompilerInfo ();
-                               compiler.Languages = AttValue ("language", child);
-                               compiler.Extensions = AttValue ("extension", child);
-                               compiler.TypeName = AttValue ("type", child);
-                               compiler.CompilerOptions = AttValue ("compilerOptions", child, true, true);
-                               compiler.WarningLevel = AttUIntValue ("warningLevel", child, -1);
-                               compiler.Init ();
-                               
-                               foreach (string l in compiler.Languages.Split(';'))
-                                       config.Compilers [l] = compiler;
-                       }
-               }
-
-               static string AttValue (string name, XmlNode node, bool optional)
-               {
-                       return AttValue (name, node, optional, false);
                }
                
-               static string AttValue (string name, XmlNode node, bool optional, bool allowEmpty)
+               protected override void InitializeDefault ()
                {
-                       return ExtractAttributeValue (name, node, optional, allowEmpty);
-               }
-
-               static bool AttBoolValue (string name, XmlNode node, bool _default)
-               {
-                       string v = AttValue (name, node, true);
-                       if (v == null)
-                               return _default;
-
-                       bool result = (v == "true");
-                       if (!result && v != "false")
-                               ThrowException ("Invalid boolean value in " + name, node);
-
-                       return result;
-               }
-
-               static int AttUIntValue (string name, XmlNode node, int _default)
-               {
-                       string v = AttValue (name, node, true);
-                       if (v == null)
-                               return _default;
-
-                       int result = 0;
-                       try {
-                               result = (int) UInt32.Parse (v);
-                       } catch {
-                               ThrowException ("Invalid number in " + name, node);
-                       }
-
-                       return result;
-               }
-
-               static string AttValue (string name, XmlNode node)
-               {
-                       return ExtractAttributeValue (name, node, true);
-               }
-
-#if false
-               // Not used for now
-               
-               static string ShortAsmName (string long_name)
-               {
-                       int i = long_name.IndexOf (',');
-                       if (i < 0)
-                               return long_name + ".dll";
-                       return long_name.Substring (0, i) + ".dll";
-               }
-#endif
-               
-               static void ThrowException (string message, XmlNode node)
-               {
-                       ThrowException (message, node);
-               }
-
-               static internal string ExtractAttributeValue (string attKey, XmlNode node)
-               {
-                       return ExtractAttributeValue (attKey, node, false);
-               }
-                       
-               static internal string ExtractAttributeValue (string attKey, XmlNode node, bool optional)
-               {
-                       return ExtractAttributeValue (attKey, node, optional, false);
+                       compilersProp = new ConfigurationProperty ("compilers", typeof (CompilerCollection), default_compilers);
                }
                
-               static internal string ExtractAttributeValue (string attKey, XmlNode node, bool optional,
-                                                             bool allowEmpty)
-               {
-                       if (node.Attributes == null) {
-                               if (optional)
+               [MonoTODO]
+                protected override void PostDeserialize ()
+                {
+                        base.PostDeserialize ();
+                }
+
+                [MonoTODO ("why override this?")]
+                protected override object GetRuntimeObject ()
+                {
+                        return this;
+                }
+
+               [ConfigurationProperty ("compilers")]
+                public CompilerCollection Compilers {
+                        get { return (CompilerCollection) base [compilersProp]; }
+                }
+
+               public CompilerInfo[] CompilerInfos {
+                       get {
+                               CompilerCollection cc = (CompilerCollection)base [compilersProp];
+                               if (cc == null)
                                        return null;
-
-                               ThrowException ("Required attribute not found: " + attKey, node);
-                       }
-
-                       XmlNode att = node.Attributes.RemoveNamedItem (attKey);
-                       if (att == null) {
-                               if (optional)
-                                       return null;
-                               ThrowException ("Required attribute not found: " + attKey, node);
-                       }
-
-                       string value = att.Value;
-                       if (!allowEmpty && value == String.Empty) {
-                               string opt = optional ? "Optional" : "Required";
-                               ThrowException (opt + " attribute is empty: " + attKey, node);
-                       }
-
-                       return value;
-               }
-       }
-
-#endif // XML_DEP
-
-       sealed class CompilationConfiguration
-       {
-               bool debug;
-               bool batch;
-               int batch_timeout;
-               string default_language = "c#";
-               bool _explicit = true;
-               int max_batch_size = 30;
-               int max_batch_file_size = 3000;
-               int num_recompiles_before_app_restart = 15;
-               bool strict;
-               string temp_directory;
-               CompilerCollection compilers;
-
-               /* Only the config. handler should create instances of this. Use GetInstance (context) */
-               public CompilationConfiguration (object p)
-               {
-                       CompilationConfiguration parent = p as CompilationConfiguration;
-                       if (parent != null)
-                               Init (parent);
-
-                       if (compilers == null)
-                               compilers = new CompilerCollection ();                  
-
-                       if (temp_directory == null)
-                               temp_directory = Path.GetTempPath ();
-               }
-
-               public CompilerInfo GetCompilerInfo (string language)
-               {
-                       return Compilers [language];
-               }
-
-               void Init (CompilationConfiguration parent)
-               {
-                       debug = parent.debug;
-                       batch = parent.batch;
-                       batch_timeout = parent.batch_timeout;
-                       default_language = parent.default_language;
-                       _explicit = parent._explicit;
-                       max_batch_size = parent.max_batch_size;
-                       max_batch_file_size = parent.max_batch_file_size;
-                       num_recompiles_before_app_restart = parent.num_recompiles_before_app_restart;
-                       strict = parent.strict;
-                       temp_directory = parent.temp_directory;
-                       compilers = new CompilerCollection (parent.compilers);
-               }
-
-               public bool Debug {
-                       get { return debug; }
-                       set { debug = value; }
-               }
-
-               public bool Batch {
-                       get { return batch; }
-                       set { batch = value; }
-               }
-
-               public int BatchTimeout {
-                       get { return batch_timeout; }
-                       set { batch_timeout = value; }
-               }
-
-               public string DefaultLanguage {
-                       get { return default_language; }
-                       set { default_language = value; }
-               }
-
-               public bool Explicit {
-                       get { return _explicit; }
-                       set { _explicit = value; }
-               }
-
-               public int MaxBatchSize {
-                       get { return max_batch_size; }
-                       set { max_batch_size = value; }
-               }
-
-               public int MaxBatchFileSize {
-                       get { return max_batch_file_size; }
-                       set { max_batch_file_size = value; }
-               }
-
-               public int NumRecompilesBeforeAppRestart {
-                       get { return num_recompiles_before_app_restart; }
-                       set { num_recompiles_before_app_restart = value; }
-               }
-
-               public bool Strict {
-                       get { return strict; }
-                       set { strict = value; }
-               }
-
-               public string TempDirectory {
-                       get { return temp_directory; }
-                       set {
-                               if (value != null && !Directory.Exists (value))
-                                       throw new ArgumentException ("Directory does not exist");
-
-                               temp_directory = value;
-                       }
-               }
-
-               public CompilerCollection Compilers {
-                       get { return compilers; }
-               }
-       }
-
-       sealed class CompilerCollection
-       {
-               Hashtable compilers;
-
-               public CompilerCollection () : this (null) {}
-
-               public CompilerCollection (CompilerCollection parent)
-               {
-                       compilers = new Hashtable (CaseInsensitiveHashCodeProvider.Default,
-                                                  CaseInsensitiveComparer.Default);
-
-                       if (parent != null && parent.compilers != null) {
-                               foreach (DictionaryEntry entry in parent.compilers)
-                                       compilers [entry.Key] = entry.Value;
+                               return cc.CompilerInfos;
                        }
                }
-
-               public CompilerInfo this [string language] {
-                       get { return compilers [language] as CompilerInfo; }
-                       set {
-                               compilers [language] = value;
-                               string [] langs = language.Split (';');
-                               foreach (string s in langs) {
-                                       string x = s.Trim ();
-                                       if (x != "")
-                                               compilers [x] = value;
-                               }
-                       }
-               }
-
-               internal Hashtable Hash {
-                       get { return compilers; }
-               }
+               
+               protected override ConfigurationPropertyCollection Properties {
+                        get { return properties; }
+                }
        }
 }
-
 #endif // NET_2_0
 
index 6f80dadd1ead1454925abf14a4089aecedea2528..e21c644cc447b6eb863135c01ecfe9a6240cbc97 100644 (file)
@@ -135,6 +135,7 @@ namespace System.CodeDom.Compiler {
                        return cg.CreateEscapedIdentifier (value);
                }
 
+#if CONFIGURATION_DEP
                [ComVisible (false)]
                [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
                public static CodeDomProvider CreateProvider (string language)
@@ -142,6 +143,7 @@ namespace System.CodeDom.Compiler {
                        CompilerInfo ci = GetCompilerInfo (language);
                        return (ci == null) ? null : ci.CreateProvider ();
                }
+#endif
 
                public virtual string CreateValidIdentifier (string value)
                {
@@ -200,27 +202,26 @@ namespace System.CodeDom.Compiler {
                        cg.GenerateCodeFromType (codeType, writer, options);
                }
 
+#if CONFIGURATION_DEP
                [ComVisible (false)]
                [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
                public static CompilerInfo[] GetAllCompilerInfo ()
                {
-                       int n = 0;
-                       if ((Config != null) && (Config.Compilers != null)) 
-                               n = Config.Compilers.Hash.Count;
-                       CompilerInfo[] ci = new CompilerInfo [n];
-                       if (n > 0)
-                               Config.Compilers.Hash.Values.CopyTo (ci, 0);
-                       return ci;
+
+                       return (Config == null) ? null : Config.CompilerInfos;
                }
 
+
                [ComVisible (false)]
                [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
                public static CompilerInfo GetCompilerInfo (string language)
                {
                        if (language == null)
                                throw new ArgumentNullException ("language");
-
-                       return (Config == null) ? null : Config.GetCompilerInfo (language);
+                       if (Config == null)
+                               return null;
+                       CompilerCollection cc = Config.Compilers;
+                       return cc[language];
                }
 
                [ComVisible (false)]
@@ -230,15 +231,11 @@ namespace System.CodeDom.Compiler {
                        if (extension == null)
                                throw new ArgumentNullException ("extension");
 
-                       if (Config != null) {
-                               foreach (DictionaryEntry de in Config.Compilers.Hash) {
-                                       CompilerInfo c = (CompilerInfo) de.Value;
-                                       if (Array.IndexOf (c.GetExtensions (), extension) != -1)
-                                               return (string) de.Key;
-                               }
-                       }
+                       if (Config != null) 
+                               return Config.Compilers.GetLanguageFromExtension (extension);
                        return null;
                }
+#endif
 
                public virtual string GetTypeOutput (CodeTypeReference type)
                {
@@ -248,6 +245,7 @@ namespace System.CodeDom.Compiler {
                        return cg.GetTypeOutput (type);
                }
 
+#if CONFIGURATION_DEP
                [ComVisible (false)]
                [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
                public static bool IsDefinedExtension (string extension)
@@ -255,12 +253,9 @@ namespace System.CodeDom.Compiler {
                        if (extension == null)
                                throw new ArgumentNullException ("extension");
 
-                       if (Config != null) {
-                               foreach (CompilerInfo c in Config.Compilers.Hash.Values) {
-                                       if (Array.IndexOf (c.GetExtensions (), extension) != -1)
-                                               return true;
-                               }
-                       }
+                       if (Config != null)
+                               return (Config.Compilers.GetCompilerInfoForExtension (extension) != null);
+                       
                        return false;
                }
 
@@ -271,10 +266,12 @@ namespace System.CodeDom.Compiler {
                        if (language == null)
                                throw new ArgumentNullException ("language");
 
-                       if (Config == null)
-                               return false;
-                       return (Config.GetCompilerInfo (language) != null);
+                       if (Config != null)
+                               return (Config.Compilers.GetCompilerInfoForLanguage (language) != null);
+
+                       return false;
                }
+#endif
 
                public virtual bool IsValidIdentifier (string value)
                {
@@ -300,9 +297,12 @@ namespace System.CodeDom.Compiler {
                        return cg.Supports (supports);
                }
 
-               static CompilationConfiguration Config {
-                       get { return ConfigurationSettings.GetConfig ("system.codedom") as CompilationConfiguration; }
+#if CONFIGURATION_DEP
+               static CodeDomConfigurationHandler Config {
+                       get { return ConfigurationManager.GetSection ("system.codedom") as CodeDomConfigurationHandler; }
                }
+#endif
+               
 #endif
        }
 }
diff --git a/mcs/class/System/System.CodeDom.Compiler/Compiler.cs b/mcs/class/System/System.CodeDom.Compiler/Compiler.cs
new file mode 100644 (file)
index 0000000..907edbd
--- /dev/null
@@ -0,0 +1,116 @@
+//
+// System.Web.Configuration.CompilerCollection
+//
+// Authors:
+//     Chris Toshok (toshok@ximian.com)
+//
+// (C) 2005 Novell, Inc (http://www.novell.com)
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0 && CONFIGURATION_DEP
+using System;
+using System.ComponentModel;
+using System.Configuration;
+
+namespace System.CodeDom.Compiler
+{
+       internal sealed class Compiler : ConfigurationElement
+       {
+               static ConfigurationProperty compilerOptionsProp;
+               static ConfigurationProperty extensionProp;
+               static ConfigurationProperty languageProp;
+               static ConfigurationProperty typeProp;
+               static ConfigurationProperty warningLevelProp;
+
+               static ConfigurationPropertyCollection properties;
+
+               static Compiler ()
+               {
+                       compilerOptionsProp = new ConfigurationProperty("compilerOptions", typeof (string), "");
+                       extensionProp = new ConfigurationProperty("extension", typeof (string), "");
+                       languageProp = new ConfigurationProperty("language", typeof (string), "", ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
+                       typeProp = new ConfigurationProperty("type", typeof (string), "", ConfigurationPropertyOptions.IsRequired);
+                       warningLevelProp = new ConfigurationProperty("warningLevel", typeof (int), 0,
+                                                                    null, //TypeDescriptor.GetConverter (typeof (int)),
+                                                                    new IntegerValidator (0, 4),
+                                                                    ConfigurationPropertyOptions.None);
+
+                       properties = new ConfigurationPropertyCollection ();
+                       properties.Add (compilerOptionsProp);
+                       properties.Add (extensionProp);
+                       properties.Add (languageProp);
+                       properties.Add (typeProp);
+                       properties.Add (warningLevelProp);
+               }
+
+               internal Compiler ()
+               {
+               }
+
+               public Compiler (string compilerOptions, string extension, string language, string type, int warningLevel)
+               {
+                       this.CompilerOptions = compilerOptions;
+                       this.Extension = extension;
+                       this.Language = language;
+                       this.Type = type;
+                       this.WarningLevel = warningLevel;
+               }
+
+               [ConfigurationProperty ("compilerOptions", DefaultValue = "")]
+               public string CompilerOptions {
+                       get { return (string) base[compilerOptionsProp]; }
+                       internal set { base[compilerOptionsProp] = value; }
+               }
+
+               [ConfigurationProperty ("extension", DefaultValue = "")]
+               public string Extension {
+                       get { return (string) base[extensionProp]; }
+                       internal set { base[extensionProp] = value; }
+               }
+
+               [ConfigurationProperty ("language", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
+               public string Language {
+                       get { return (string) base[languageProp]; }
+                       internal set { base[languageProp] = value; }
+               }
+
+               [ConfigurationProperty ("type", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired)]
+               public string Type {
+                       get { return (string) base[typeProp]; }
+                       internal set { base[typeProp] = value; }
+               }
+
+               [IntegerValidator (MinValue = 0, MaxValue = 4)]
+               [ConfigurationProperty ("warningLevel", DefaultValue = "0")]
+               public int WarningLevel {
+                       get { return (int) base[warningLevelProp]; }
+                       internal set { base[warningLevelProp] = value; }
+               }
+
+               protected override ConfigurationPropertyCollection Properties {
+                       get { return properties; }
+               }
+       }
+}
+#endif
diff --git a/mcs/class/System/System.CodeDom.Compiler/CompilerCollection.cs b/mcs/class/System/System.CodeDom.Compiler/CompilerCollection.cs
new file mode 100644 (file)
index 0000000..f635a29
--- /dev/null
@@ -0,0 +1,202 @@
+//
+// System.Web.Configuration.CompilerCollection
+//
+// Authors:
+//     Chris Toshok (toshok@ximian.com)
+//
+// (C) 2005 Novell, Inc (http://www.novell.com)
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0 && CONFIGURATION_DEP
+
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+
+namespace System.CodeDom.Compiler
+{
+       [ConfigurationCollection (typeof (Compiler), AddItemName = "compiler", CollectionType = ConfigurationElementCollectionType.BasicMap)]
+       internal sealed class CompilerCollection : ConfigurationElementCollection
+       {
+               static ConfigurationPropertyCollection properties;
+               static SortedDictionary<string, CompilerInfo> compiler_infos_by_language;
+               static SortedDictionary<string, CompilerInfo> compiler_infos_by_extension;
+               
+               static CompilerCollection ()
+               {
+                       properties = new ConfigurationPropertyCollection ();
+                       compiler_infos_by_language = new SortedDictionary <string, CompilerInfo> ();
+                       compiler_infos_by_extension = new SortedDictionary <string, CompilerInfo> ();
+                       
+                       CompilerInfo compiler = new CompilerInfo ();
+                        compiler.Languages = "c#;cs;csharp";
+                        compiler.Extensions = ".cs";
+                        compiler.TypeName = "Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
+                       AddCompilerInfo (compiler);
+
+                       compiler = new CompilerInfo ();
+                       compiler.Languages = "vb;vbs;visualbasic;vbscript";
+                        compiler.Extensions = ".vb";
+                        compiler.TypeName = "Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
+                       AddCompilerInfo (compiler);
+
+                       compiler = new CompilerInfo ();
+                        compiler.Languages = "js;jscript;javascript";
+                        compiler.Extensions = ".js";
+                        compiler.TypeName = "Microsoft.JScript.JScriptCodeProvider, Microsoft.JScript, Version=8.0.1100.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
+                       AddCompilerInfo (compiler);
+
+                       compiler = new CompilerInfo ();
+                        compiler.Languages = "vj#;vjs;vjsharp";
+                        compiler.Extensions = ".jsl;.java";
+                        compiler.TypeName = "Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
+                       AddCompilerInfo (compiler);
+
+                       compiler = new CompilerInfo ();
+                        compiler.Languages = "c++;mc;cpp";
+                        compiler.Extensions = ".h";
+                        compiler.TypeName = "Microsoft.VisualC.CppCodeProvider, CppCodeProvider, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
+                       AddCompilerInfo (compiler);
+               }
+
+               public CompilerCollection ()
+               {
+               }
+
+               static void AddCompilerInfo (CompilerInfo ci)
+               {
+                       ci.Init ();
+                       foreach (string l in ci.Languages.Split (';'))
+                               compiler_infos_by_language.Add (l, ci);
+                       foreach (string e in ci.Extensions.Split (';'))
+                               compiler_infos_by_extension.Add (e, ci);
+               }
+
+               static void AddCompilerInfo (Compiler compiler)
+               {
+                       CompilerInfo ci = new CompilerInfo ();
+                       ci.Languages = compiler.Language;
+                       ci.Extensions = compiler.Extension;
+                       ci.TypeName = compiler.Type;
+                       AddCompilerInfo (ci);
+               }
+               
+               protected override void BaseAdd (ConfigurationElement element)
+               {
+                       Compiler compiler = element as Compiler;
+                       if (compiler != null)
+                               AddCompilerInfo (compiler);
+                       base.BaseAdd (element);
+               }
+               
+               protected override bool ThrowOnDuplicate {
+                        get { return false; }
+                }
+               
+               protected override ConfigurationElement CreateNewElement ()
+               {
+                       return new Compiler ();
+               }
+
+               public CompilerInfo GetCompilerInfoForLanguage (string language)
+               {
+                       return compiler_infos_by_language [language];
+               }
+
+               public CompilerInfo GetCompilerInfoForExtension (string extension)
+               {
+                       return compiler_infos_by_extension [extension];
+               }
+
+               public string GetLanguageFromExtension (string extension)
+               {
+                       CompilerInfo ci = GetCompilerInfoForExtension (extension);
+                       if (ci == null)
+                               return null;
+                       foreach (KeyValuePair <string, CompilerInfo> kvp in compiler_infos_by_language)
+                               if (ci.Equals (kvp.Value))
+                                       return kvp.Key;
+                       return null;
+               }
+               
+               public Compiler Get (int index)
+               {
+                       return (Compiler) BaseGet (index);
+               }
+
+               public Compiler Get (string language)
+               {
+                       return (Compiler) BaseGet (language);
+               }
+
+               protected override object GetElementKey (ConfigurationElement element)
+               {
+                       return ((Compiler)element).Language;
+               }
+
+               public string GetKey (int index)
+               {
+                       return (string)BaseGetKey (index);
+               }
+
+               public string[ ] AllKeys {
+                       get {
+                               string[] ret = new string [compiler_infos_by_language.Keys.Count];
+                               compiler_infos_by_language.Keys.CopyTo (ret, 0);
+                               return ret;
+                       }
+               }
+               
+               public override ConfigurationElementCollectionType CollectionType {
+                       get { return ConfigurationElementCollectionType.BasicMap; }
+               }
+
+               protected override string ElementName {
+                       get { return "compiler"; }
+               }
+
+               protected override ConfigurationPropertyCollection Properties {
+                       get { return properties; }
+               }
+
+               public Compiler this[int index] {
+                       get { return (Compiler) BaseGet (index); }
+               }
+
+               public new CompilerInfo this[string language] {
+                       get {
+                               return compiler_infos_by_language [language];
+                       }
+               }
+
+               public CompilerInfo[] CompilerInfos {
+                       get {
+                               CompilerInfo[] ret = new CompilerInfo [compiler_infos_by_language.Values.Count];
+                               compiler_infos_by_language.Values.CopyTo (ret, 0);
+                               return ret;
+                       }
+               }
+       }
+}
+#endif
index 4db29edeb88a138028635bbc536c349051f22176..7832705dc53d2bd9d8fcc1beceebcd1ed6569181 100644 (file)
@@ -118,6 +118,8 @@ System.CodeDom.Compiler/CodeDomProvider.cs
 System.CodeDom.Compiler/CodeGenerator.cs
 System.CodeDom.Compiler/CodeGeneratorOptions.cs
 System.CodeDom.Compiler/CodeParser.cs
+System.CodeDom.Compiler/Compiler.cs
+System.CodeDom.Compiler/CompilerCollection.cs
 System.CodeDom.Compiler/CompilerErrorCollection.cs
 System.CodeDom.Compiler/CompilerError.cs
 System.CodeDom.Compiler/CompilerInfo.cs