2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System / System.CodeDom.Compiler / CompilerInfo.cs
blob09c5ad954ca25bce7f055785928887d2089cc72a
1 //
2 // System.CodeDom.Compiler CompilerInfo class
3 //
4 // Author:
5 // Marek Safar (marek.safar@seznam.cz)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //
8 // Copyright (c) 2004,2005 Novell, Inc. (http://www.novell.com)
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #if NET_2_0
34 using System.Configuration;
35 using System.Collections.Generic;
36 using System.Reflection;
37 using System.Security.Permissions;
39 namespace System.CodeDom.Compiler {
41 [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
42 public sealed class CompilerInfo
44 internal string Languages;
45 internal string Extensions;
46 internal string TypeName;
47 internal int WarningLevel;
48 internal string CompilerOptions;
49 internal Dictionary <string, string> ProviderOptions;
51 bool inited;
52 Type type;
54 internal CompilerInfo ()
58 internal void Init ()
60 if (inited)
61 return;
63 inited = true;
64 type = Type.GetType (TypeName);
65 if (type == null)
66 return;
68 if (!typeof (CodeDomProvider).IsAssignableFrom (type))
69 type = null;
72 public Type CodeDomProviderType {
73 get {
74 if (type == null) {
75 type = Type.GetType (TypeName, false);
76 #if CONFIGURATION_DEP
77 if (type == null)
78 throw new ConfigurationErrorsException ("Unable to locate compiler type '" + TypeName + "'");
79 #endif
82 return type;
87 public bool IsCodeDomProviderTypeValid {
88 get { return type != null; }
91 public CompilerParameters CreateDefaultCompilerParameters ()
93 CompilerParameters cparams = new CompilerParameters ();
94 if (CompilerOptions == null)
95 cparams.CompilerOptions = String.Empty;
96 else
97 cparams.CompilerOptions = CompilerOptions;
98 cparams.WarningLevel = WarningLevel;
100 return cparams;
103 public CodeDomProvider CreateProvider ()
105 return CreateProvider (ProviderOptions);
108 #if NET_4_0
109 public
110 #endif
111 CodeDomProvider CreateProvider (IDictionary<string, string> providerOptions)
113 Type providerType = CodeDomProviderType;
114 if (providerOptions != null && providerOptions.Count > 0) {
115 ConstructorInfo ctor = providerType.GetConstructor (new [] { typeof (IDictionary <string, string>) });
116 if (ctor != null)
117 return (CodeDomProvider) ctor.Invoke (new object[] { providerOptions });
120 return (CodeDomProvider) Activator.CreateInstance (providerType);
123 public override bool Equals (object o)
125 if (!(o is CompilerInfo))
126 return false;
128 CompilerInfo c = (CompilerInfo) o;
129 return c.TypeName == TypeName;
132 public override int GetHashCode ()
134 return TypeName.GetHashCode ();
137 public string [] GetExtensions ()
139 return Extensions.Split (';');
142 public string [] GetLanguages ()
144 return Languages.Split (';');
148 #endif