New tests.
[mono.git] / mcs / class / System / System.CodeDom.Compiler / CompilerInfo.cs
index 269cc54bdff8320fee9f112b9751cae3375dc519..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,9 +70,20 @@ 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; }
                }
@@ -86,7 +102,22 @@ namespace System.CodeDom.Compiler {
 
                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)