2 // System.CodeDom.Compiler CompilerInfo class
5 // Marek Safar (marek.safar@seznam.cz)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // Copyright (c) 2004,2005 Novell, Inc. (http://www.novell.com)
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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 using System.Configuration;
33 using System.Collections.Generic;
34 using System.Reflection;
35 using System.Security.Permissions;
37 namespace System.CodeDom.Compiler {
39 [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
40 public sealed class CompilerInfo
42 internal string Languages;
43 internal string Extensions;
44 internal string TypeName;
45 internal int WarningLevel;
46 internal string CompilerOptions;
47 internal Dictionary <string, string> ProviderOptions;
52 internal CompilerInfo ()
62 type = Type.GetType (TypeName);
66 if (!typeof (CodeDomProvider).IsAssignableFrom (type))
70 public Type CodeDomProviderType {
73 type = Type.GetType (TypeName, false);
76 throw new ConfigurationErrorsException ("Unable to locate compiler type '" + TypeName + "'");
85 public bool IsCodeDomProviderTypeValid {
86 get { return type != null; }
89 public CompilerParameters CreateDefaultCompilerParameters ()
91 CompilerParameters cparams = new CompilerParameters ();
92 if (CompilerOptions == null)
93 cparams.CompilerOptions = String.Empty;
95 cparams.CompilerOptions = CompilerOptions;
96 cparams.WarningLevel = WarningLevel;
101 public CodeDomProvider CreateProvider ()
103 return CreateProvider (ProviderOptions);
107 CodeDomProvider CreateProvider (IDictionary<string, string> providerOptions)
109 Type providerType = CodeDomProviderType;
110 if (providerOptions != null && providerOptions.Count > 0) {
111 ConstructorInfo ctor = providerType.GetConstructor (new [] { typeof (IDictionary <string, string>) });
113 return (CodeDomProvider) ctor.Invoke (new object[] { providerOptions });
116 return (CodeDomProvider) Activator.CreateInstance (providerType);
119 public override bool Equals (object o)
121 if (!(o is CompilerInfo))
124 CompilerInfo c = (CompilerInfo) o;
125 return c.TypeName == TypeName;
128 public override int GetHashCode ()
130 return TypeName.GetHashCode ();
133 public string [] GetExtensions ()
135 return Extensions.Split (';');
138 public string [] GetLanguages ()
140 return Languages.Split (';');