New tests.
[mono.git] / mcs / class / System / System.CodeDom.Compiler / CompilerInfo.cs
index 76c0a0523ec7a6d25e040f6f5aeae37e778d7f81..09c5ad954ca25bce7f055785928887d2089cc72a 100644 (file)
 
 #if NET_2_0
 
+using System.Configuration;
+using System.Collections.Generic;
+using System.Reflection;
 using System.Security.Permissions;
 
 namespace System.CodeDom.Compiler {
 
        [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
-       public sealed class CompilerInfo {
-
+       public sealed class CompilerInfo
+       {
                internal string Languages;
                internal string Extensions;
                internal string TypeName;
                internal int WarningLevel;
                internal string CompilerOptions;
+               internal Dictionary <string, string> ProviderOptions;
+               
                bool inited;
                Type type;
 
@@ -65,22 +70,54 @@ namespace System.CodeDom.Compiler {
                }
 
                public Type CodeDomProviderType {
-                       get { return type; }
+                       get {
+                               if (type == null) {
+                                       type = Type.GetType (TypeName, false);
+#if CONFIGURATION_DEP
+                                       if (type == null)
+                                               throw new ConfigurationErrorsException ("Unable to locate compiler type '" + TypeName + "'");
+#endif
+                               }
+                               
+                               return type;
+                       }
                }
 
+               
                public bool IsCodeDomProviderTypeValid {
                        get { return type != null; }
                }
 
-               [MonoTODO]
                public CompilerParameters CreateDefaultCompilerParameters ()
                {
-                       throw new NotImplementedException ();
+                       CompilerParameters cparams = new CompilerParameters ();
+                       if (CompilerOptions == null)
+                               cparams.CompilerOptions = String.Empty;
+                       else
+                               cparams.CompilerOptions = CompilerOptions;
+                       cparams.WarningLevel = WarningLevel;
+
+                       return cparams;
                }
 
                public CodeDomProvider CreateProvider ()
                {
-                       return (CodeDomProvider) Activator.CreateInstance (type);
+                       return CreateProvider (ProviderOptions);
+               }
+
+#if NET_4_0
+               public          
+#endif
+               CodeDomProvider CreateProvider (IDictionary<string, string> providerOptions)
+               {
+                       Type providerType = CodeDomProviderType;
+                       if (providerOptions != null && providerOptions.Count > 0) {
+                               ConstructorInfo ctor = providerType.GetConstructor (new [] { typeof (IDictionary <string, string>) });
+                               if (ctor != null)
+                                       return (CodeDomProvider) ctor.Invoke (new object[] { providerOptions });
+                       }
+                       
+                       return (CodeDomProvider) Activator.CreateInstance (providerType);
                }
 
                public override bool Equals (object o)