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.
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;
54 internal CompilerInfo ()
64 type = Type.GetType (TypeName);
68 if (!typeof (CodeDomProvider).IsAssignableFrom (type))
72 public Type CodeDomProviderType {
75 type = Type.GetType (TypeName, false);
78 throw new ConfigurationErrorsException ("Unable to locate compiler type '" + TypeName + "'");
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;
97 cparams.CompilerOptions = CompilerOptions;
98 cparams.WarningLevel = WarningLevel;
103 public CodeDomProvider CreateProvider ()
105 return CreateProvider (ProviderOptions);
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>) });
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))
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 (';');