1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
//------------------------------------------------------------------------------
// <copyright file="CompilerInfo.cs" company="Microsoft">
//
// <OWNER>[....]</OWNER>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.CodeDom.Compiler {
using System;
using System.Reflection;
using System.Security.Permissions;
using System.CodeDom.Compiler;
using System.Configuration;
using System.Collections.Generic;
using System.Diagnostics;
[PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]
public sealed class CompilerInfo {
internal String _codeDomProviderTypeName; // This can never by null
internal CompilerParameters _compilerParams; // This can never by null
internal String[] _compilerLanguages; // This can never by null
internal String[] _compilerExtensions; // This can never by null
internal String configFileName;
internal IDictionary<string, string> _providerOptions; // This can never be null
internal int configFileLineNumber;
internal Boolean _mapped;
private Type type;
private CompilerInfo() {} // Not createable
public String[] GetLanguages() {
return CloneCompilerLanguages();
}
public String[] GetExtensions() {
return CloneCompilerExtensions();
}
public Type CodeDomProviderType {
get {
if( type == null) {
lock(this) {
if( type == null) {
type = Type.GetType(_codeDomProviderTypeName);
if (type == null) {
if( configFileName == null) {
throw new ConfigurationErrorsException(SR.GetString(SR.Unable_To_Locate_Type,
_codeDomProviderTypeName, string.Empty, 0));
}
else {
throw new ConfigurationErrorsException(SR.GetString(SR.Unable_To_Locate_Type,
_codeDomProviderTypeName), configFileName, configFileLineNumber);
}
}
}
}
}
return type;
}
}
public bool IsCodeDomProviderTypeValid {
get {
Type type = Type.GetType(_codeDomProviderTypeName);
return (type != null);
}
}
public CodeDomProvider CreateProvider() {
// if the provider defines an IDictionary<string, string> ctor and
// provider options have been provided then call that and give it the
// provider options dictionary. Otherwise call the normal one.
Debug.Assert(_providerOptions != null, "Created CompilerInfo w/ null _providerOptions");
if (_providerOptions.Count > 0) {
ConstructorInfo ci = CodeDomProviderType.GetConstructor(new Type[] { typeof(IDictionary<string, string>) });
if (ci != null) {
return (CodeDomProvider)ci.Invoke(new object[] { _providerOptions });
}
}
return (CodeDomProvider)Activator.CreateInstance(CodeDomProviderType);
}
public CodeDomProvider CreateProvider(IDictionary<String, String> providerOptions)
{
if (providerOptions == null)
throw new ArgumentNullException("providerOptions");
ConstructorInfo constructor = CodeDomProviderType.GetConstructor(new Type[] { typeof(IDictionary<string, string>) });
if (constructor != null) {
return (CodeDomProvider)constructor.Invoke(new object[] { providerOptions });
}
else
throw new InvalidOperationException(SR.GetString(SR.Provider_does_not_support_options, CodeDomProviderType.ToString()));
}
public CompilerParameters CreateDefaultCompilerParameters() {
return CloneCompilerParameters();
}
internal CompilerInfo(CompilerParameters compilerParams, String codeDomProviderTypeName, String[] compilerLanguages, String[] compilerExtensions) {
_compilerLanguages = compilerLanguages;
_compilerExtensions = compilerExtensions;
_codeDomProviderTypeName = codeDomProviderTypeName;
if (compilerParams == null)
compilerParams = new CompilerParameters();
_compilerParams = compilerParams;
}
internal CompilerInfo(CompilerParameters compilerParams, String codeDomProviderTypeName) {
_codeDomProviderTypeName = codeDomProviderTypeName;
if (compilerParams == null)
compilerParams = new CompilerParameters();
_compilerParams = compilerParams;
}
public override int GetHashCode() {
return _codeDomProviderTypeName.GetHashCode();
}
public override bool Equals(Object o) {
CompilerInfo other = o as CompilerInfo;
if (o == null)
return false;
return CodeDomProviderType == other.CodeDomProviderType &&
CompilerParams.WarningLevel == other.CompilerParams.WarningLevel &&
CompilerParams.IncludeDebugInformation == other.CompilerParams.IncludeDebugInformation &&
CompilerParams.CompilerOptions == other.CompilerParams.CompilerOptions;
}
private CompilerParameters CloneCompilerParameters() {
CompilerParameters copy = new CompilerParameters();
copy.IncludeDebugInformation = _compilerParams.IncludeDebugInformation;
copy.TreatWarningsAsErrors = _compilerParams.TreatWarningsAsErrors;
copy.WarningLevel = _compilerParams.WarningLevel;
copy.CompilerOptions = _compilerParams.CompilerOptions;
return copy;
}
private String[] CloneCompilerLanguages() {
String[] compilerLanguages = new String[_compilerLanguages.Length];
Array.Copy(_compilerLanguages, compilerLanguages, _compilerLanguages.Length);
return compilerLanguages;
}
private String[] CloneCompilerExtensions() {
String[] compilerExtensions = new String[_compilerExtensions.Length];
Array.Copy(_compilerExtensions, compilerExtensions, _compilerExtensions.Length);
return compilerExtensions;
}
internal CompilerParameters CompilerParams {
get {
return _compilerParams;
}
}
// @
internal IDictionary<string, string> ProviderOptions {
get {
return _providerOptions;
}
}
}
}
|