New tests.
[mono.git] / mcs / class / System / System.CodeDom.Compiler / CompilerInfo.cs
index 4363e7235bd1b3f67fbb0dce38cf85f14fd888a9..09c5ad954ca25bce7f055785928887d2089cc72a 100644 (file)
 //
 
 #if NET_2_0
-namespace System.CodeDom.Compiler
-{
+
+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
        {
                internal string Languages;
@@ -39,6 +46,8 @@ namespace System.CodeDom.Compiler
                internal string TypeName;
                internal int WarningLevel;
                internal string CompilerOptions;
+               internal Dictionary <string, string> ProviderOptions;
+               
                bool inited;
                Type type;
 
@@ -46,7 +55,7 @@ namespace System.CodeDom.Compiler
                {
                }
 
-               void Init ()
+               internal void Init ()
                {
                        if (inited)
                                return;
@@ -61,16 +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; }
                }
 
+               public CompilerParameters CreateDefaultCompilerParameters ()
+               {
+                       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)