mscorlib(4.0.0.0) API with additions
CompilerInfo.cs
3 using System.Reflection;
5 
7 {
9  [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
10  public sealed class CompilerInfo
11  {
12  internal string _codeDomProviderTypeName;
13 
14  internal CompilerParameters _compilerParams;
15 
16  internal string[] _compilerLanguages;
17 
18  internal string[] _compilerExtensions;
19 
20  internal string configFileName;
21 
22  internal IDictionary<string, string> _providerOptions;
23 
24  internal int configFileLineNumber;
25 
26  internal bool _mapped;
27 
28  private Type type;
29 
35  {
36  get
37  {
38  if (type == null)
39  {
40  lock (this)
41  {
42  if (type == null)
43  {
44  type = Type.GetType(_codeDomProviderTypeName);
45  if (type == null)
46  {
47  if (configFileName == null)
48  {
49  throw new ConfigurationErrorsException(SR.GetString("Unable_To_Locate_Type", _codeDomProviderTypeName, string.Empty, 0));
50  }
51  throw new ConfigurationErrorsException(SR.GetString("Unable_To_Locate_Type", _codeDomProviderTypeName), configFileName, configFileLineNumber);
52  }
53  }
54  }
55  }
56  return type;
57  }
58  }
59 
63  public bool IsCodeDomProviderTypeValid
64  {
65  get
66  {
67  Type left = Type.GetType(_codeDomProviderTypeName);
68  return left != null;
69  }
70  }
71 
72  internal CompilerParameters CompilerParams => _compilerParams;
73 
74  internal IDictionary<string, string> ProviderOptions => _providerOptions;
75 
76  private CompilerInfo()
77  {
78  }
79 
82  public string[] GetLanguages()
83  {
84  return CloneCompilerLanguages();
85  }
86 
89  public string[] GetExtensions()
90  {
91  return CloneCompilerExtensions();
92  }
93 
97  {
98  if (_providerOptions.Count > 0)
99  {
101  {
103  });
104  if (constructor != null)
105  {
106  return (CodeDomProvider)constructor.Invoke(new object[1]
107  {
108  _providerOptions
109  });
110  }
111  }
113  }
114 
122  {
123  if (providerOptions == null)
124  {
125  throw new ArgumentNullException("providerOptions");
126  }
128  {
130  });
131  if (constructor != null)
132  {
133  return (CodeDomProvider)constructor.Invoke(new object[1]
134  {
135  providerOptions
136  });
137  }
138  throw new InvalidOperationException(SR.GetString("Provider_does_not_support_options", CodeDomProviderType.ToString()));
139  }
140 
144  {
145  return CloneCompilerParameters();
146  }
147 
148  internal CompilerInfo(CompilerParameters compilerParams, string codeDomProviderTypeName, string[] compilerLanguages, string[] compilerExtensions)
149  {
150  _compilerLanguages = compilerLanguages;
151  _compilerExtensions = compilerExtensions;
152  _codeDomProviderTypeName = codeDomProviderTypeName;
153  if (compilerParams == null)
154  {
155  compilerParams = new CompilerParameters();
156  }
157  _compilerParams = compilerParams;
158  }
159 
160  internal CompilerInfo(CompilerParameters compilerParams, string codeDomProviderTypeName)
161  {
162  _codeDomProviderTypeName = codeDomProviderTypeName;
163  if (compilerParams == null)
164  {
165  compilerParams = new CompilerParameters();
166  }
167  _compilerParams = compilerParams;
168  }
169 
172  public override int GetHashCode()
173  {
174  return _codeDomProviderTypeName.GetHashCode();
175  }
176 
181  public override bool Equals(object o)
182  {
183  CompilerInfo compilerInfo = o as CompilerInfo;
184  if (o == null)
185  {
186  return false;
187  }
188  if (CodeDomProviderType == compilerInfo.CodeDomProviderType && CompilerParams.WarningLevel == compilerInfo.CompilerParams.WarningLevel && CompilerParams.IncludeDebugInformation == compilerInfo.CompilerParams.IncludeDebugInformation)
189  {
190  return CompilerParams.CompilerOptions == compilerInfo.CompilerParams.CompilerOptions;
191  }
192  return false;
193  }
194 
195  private CompilerParameters CloneCompilerParameters()
196  {
197  CompilerParameters compilerParameters = new CompilerParameters();
198  compilerParameters.IncludeDebugInformation = _compilerParams.IncludeDebugInformation;
199  compilerParameters.TreatWarningsAsErrors = _compilerParams.TreatWarningsAsErrors;
200  compilerParameters.WarningLevel = _compilerParams.WarningLevel;
201  compilerParameters.CompilerOptions = _compilerParams.CompilerOptions;
202  return compilerParameters;
203  }
204 
205  private string[] CloneCompilerLanguages()
206  {
207  string[] array = new string[_compilerLanguages.Length];
208  Array.Copy(_compilerLanguages, array, _compilerLanguages.Length);
209  return array;
210  }
211 
212  private string[] CloneCompilerExtensions()
213  {
214  string[] array = new string[_compilerExtensions.Length];
215  Array.Copy(_compilerExtensions, array, _compilerExtensions.Length);
216  return array;
217  }
218  }
219 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
bool IsCodeDomProviderTypeValid
Returns a value indicating whether the language provider implementation is configured on the computer...
Definition: CompilerInfo.cs:64
Discovers the attributes of a class constructor and provides access to constructor metadata.
Definition: __Canon.cs:3
bool IncludeDebugInformation
Gets or sets a value indicating whether to include debug information in the compiled executable.
string [] GetLanguages()
Gets the language names supported by the language provider.
Definition: CompilerInfo.cs:82
override string ToString()
Returns a String representing the name of the current Type.
Definition: Type.cs:2788
string [] GetExtensions()
Returns the file name extensions supported by the language provider.
Definition: CompilerInfo.cs:89
ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
Searches for a constructor whose parameters match the specified argument types and modifiers,...
Definition: Type.cs:1378
Represents the parameters used to invoke a compiler.
override bool Equals(object o)
Determines whether the specified object represents the same language provider and compiler settings a...
Contains methods to create types of objects locally or remotely, or obtain references to existing rem...
Definition: Activator.cs:21
string CompilerOptions
Gets or sets optional command-line arguments to use when invoking the compiler.
SecurityAction
Specifies the security actions that can be performed using declarative security.
CompilerParameters CreateDefaultCompilerParameters()
Gets the configured compiler settings for the language provider implementation.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
CodeDomProvider CreateProvider()
Returns a T:System.CodeDom.Compiler.CodeDomProvider instance for the current language provider settin...
Definition: CompilerInfo.cs:96
int WarningLevel
Gets or sets the warning level at which the compiler aborts compilation.
override int GetHashCode()
Returns the hash code for the current instance.
bool TreatWarningsAsErrors
Gets or sets a value indicating whether to treat warnings as errors.
static object CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture)
Creates an instance of the specified type using the constructor that best matches the specified param...
Definition: Activator.cs:57
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Definition: Array.cs:1275
CodeDomProvider CreateProvider(IDictionary< string, string > providerOptions)
Returns a T:System.CodeDom.Compiler.CodeDomProvider instance for the current language provider settin...
abstract object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
When implemented in a derived class, invokes the constructor reflected by this ConstructorInfo with t...
The exception that is thrown when a method call is invalid for the object's current state.
Provides a base class for T:System.CodeDom.Compiler.CodeDomProvider implementations....
static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Gets the T:System.Type with the specified name, specifying whether to throw an exception if the type ...
Definition: Type.cs:853
Represents the configuration settings of a language provider. This class cannot be inherited.
Definition: CompilerInfo.cs:10
Type CodeDomProviderType
Gets the type of the configured T:System.CodeDom.Compiler.CodeDomProvider implementation.
Definition: CompilerInfo.cs:35