PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/referencesource/System/compmod/system/codedom/compiler/CompilerParameters.cs

https://github.com/pruiz/mono
C# | 363 lines | 219 code | 28 blank | 116 comment | 12 complexity | fbd3e958de11a58b0df03e131d5b90d5 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. //------------------------------------------------------------------------------
  2. // <copyright file="CompilerParameters.cs" company="Microsoft">
  3. //
  4. // <OWNER>Microsoft</OWNER>
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // </copyright>
  7. //------------------------------------------------------------------------------
  8. namespace System.CodeDom.Compiler {
  9. using System;
  10. using System.CodeDom;
  11. using System.Collections;
  12. using System.Collections.Specialized;
  13. using Microsoft.Win32;
  14. using Microsoft.Win32.SafeHandles;
  15. using System.Runtime.InteropServices;
  16. using System.Security.Permissions;
  17. using System.Security.Policy;
  18. using System.Runtime.Serialization;
  19. using System.Runtime.Versioning;
  20. /// <devdoc>
  21. /// <para>
  22. /// Represents the parameters used in to invoke the compiler.
  23. /// </para>
  24. /// </devdoc>
  25. [PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]
  26. [PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
  27. [Serializable]
  28. public class CompilerParameters {
  29. [OptionalField]
  30. private string coreAssemblyFileName = String.Empty;
  31. private StringCollection assemblyNames = new StringCollection();
  32. [OptionalField]
  33. private StringCollection embeddedResources = new StringCollection();
  34. [OptionalField]
  35. private StringCollection linkedResources = new StringCollection();
  36. private string outputName;
  37. private string mainClass;
  38. private bool generateInMemory = false;
  39. private bool includeDebugInformation = false;
  40. private int warningLevel = -1; // -1 means not set (use compiler default)
  41. private string compilerOptions;
  42. private string win32Resource;
  43. private bool treatWarningsAsErrors = false;
  44. private bool generateExecutable = false;
  45. private TempFileCollection tempFiles;
  46. [NonSerializedAttribute]
  47. #if MONO
  48. IntPtr userToken;
  49. #else
  50. private SafeUserTokenHandle userToken;
  51. #endif
  52. private Evidence evidence = null;
  53. /// <devdoc>
  54. /// <para>
  55. /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerParameters'/>.
  56. /// </para>
  57. /// </devdoc>
  58. [ResourceExposure(ResourceScope.None)]
  59. [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
  60. public CompilerParameters() :
  61. this(null, null) {
  62. }
  63. /// <devdoc>
  64. /// <para>
  65. /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerParameters'/> using the specified
  66. /// assembly names.
  67. /// </para>
  68. /// </devdoc>
  69. [ResourceExposure(ResourceScope.None)]
  70. [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
  71. public CompilerParameters(string[] assemblyNames) :
  72. this(assemblyNames, null, false) {
  73. }
  74. /// <devdoc>
  75. /// <para>
  76. /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerParameters'/> using the specified
  77. /// assembly names and output name.
  78. /// </para>
  79. /// </devdoc>
  80. [ResourceExposure(ResourceScope.Machine)]
  81. [ResourceConsumption(ResourceScope.Machine)]
  82. public CompilerParameters(string[] assemblyNames, string outputName) :
  83. this(assemblyNames, outputName, false) {
  84. }
  85. /// <devdoc>
  86. /// <para>
  87. /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerParameters'/> using the specified
  88. /// assembly names, output name and a whether to include debug information flag.
  89. /// </para>
  90. /// </devdoc>
  91. [ResourceExposure(ResourceScope.Machine)]
  92. public CompilerParameters(string[] assemblyNames, string outputName, bool includeDebugInformation) {
  93. if (assemblyNames != null) {
  94. ReferencedAssemblies.AddRange(assemblyNames);
  95. }
  96. this.outputName = outputName;
  97. this.includeDebugInformation = includeDebugInformation;
  98. }
  99. /// <summary>
  100. /// The "core" or "standard" assembly that contains basic types such as <code>Object</code>, <code>Int32</code> and the like
  101. /// that is to be used for the compilation.<br />
  102. /// If the value of this property is an empty string (or <code>null</code>), the default core assembly will be used by the
  103. /// compiler (depending on the compiler version this may be <code>mscorlib.dll</code> or <code>System.Runtime.dll</code> in
  104. /// a Framework or reference assembly directory).<br />
  105. /// If the value of this property is not empty, CodeDOM will emit compiler options to not reference <em>any</em> assemblies
  106. /// implicitly during compilation. It will also explicitly reference the assembly file specified in this property.<br />
  107. /// For compilers that only implicitly reference the "core" or "standard" assembly by default, this option can be used on its own.
  108. /// For compilers that implicitly reference more assemblies on top of the "core" / "standard" assembly, using this option may require
  109. /// specifying additional entries in the <code>System.CodeDom.Compiler.<bold>ReferencedAssemblies</bold></code> collection.<br />
  110. /// Note: An <code>ICodeCompiler</code> / <code>CoodeDomProvider</code> implementation may choose to ignore this property.
  111. /// </summary>
  112. public string CoreAssemblyFileName {
  113. get {
  114. return coreAssemblyFileName;
  115. }
  116. set {
  117. coreAssemblyFileName = value;
  118. }
  119. }
  120. /// <devdoc>
  121. /// <para>
  122. /// Gets or sets whether to generate an executable.
  123. /// </para>
  124. /// </devdoc>
  125. public bool GenerateExecutable {
  126. get {
  127. return generateExecutable;
  128. }
  129. set {
  130. generateExecutable = value;
  131. }
  132. }
  133. /// <devdoc>
  134. /// <para>
  135. /// Gets or sets whether to generate in memory.
  136. /// </para>
  137. /// </devdoc>
  138. public bool GenerateInMemory {
  139. get {
  140. return generateInMemory;
  141. }
  142. set {
  143. generateInMemory = value;
  144. }
  145. }
  146. /// <devdoc>
  147. /// <para>
  148. /// Gets or sets the assemblies referenced by the source to compile.
  149. /// </para>
  150. /// </devdoc>
  151. public StringCollection ReferencedAssemblies {
  152. get {
  153. return assemblyNames;
  154. }
  155. }
  156. /// <devdoc>
  157. /// <para>
  158. /// Gets or sets the main class.
  159. /// </para>
  160. /// </devdoc>
  161. public string MainClass {
  162. get {
  163. return mainClass;
  164. }
  165. set {
  166. mainClass = value;
  167. }
  168. }
  169. /// <devdoc>
  170. /// <para>
  171. /// Gets or sets the output assembly.
  172. /// </para>
  173. /// </devdoc>
  174. public string OutputAssembly {
  175. [ResourceExposure(ResourceScope.Machine)]
  176. get {
  177. return outputName;
  178. }
  179. [ResourceExposure(ResourceScope.Machine)]
  180. set {
  181. outputName = value;
  182. }
  183. }
  184. /// <devdoc>
  185. /// <para>
  186. /// Gets or sets the temp files.
  187. /// </para>
  188. /// </devdoc>
  189. public TempFileCollection TempFiles {
  190. get {
  191. if (tempFiles == null)
  192. tempFiles = new TempFileCollection();
  193. return tempFiles;
  194. }
  195. set {
  196. tempFiles = value;
  197. }
  198. }
  199. /// <devdoc>
  200. /// <para>
  201. /// Gets or sets whether to include debug information in the compiled
  202. /// executable.
  203. /// </para>
  204. /// </devdoc>
  205. public bool IncludeDebugInformation {
  206. get {
  207. return includeDebugInformation;
  208. }
  209. set {
  210. includeDebugInformation = value;
  211. }
  212. }
  213. /// <devdoc>
  214. /// <para>[To be supplied.]</para>
  215. /// </devdoc>
  216. public bool TreatWarningsAsErrors {
  217. get {
  218. return treatWarningsAsErrors;
  219. }
  220. set {
  221. treatWarningsAsErrors = value;
  222. }
  223. }
  224. /// <devdoc>
  225. /// <para>[To be supplied.]</para>
  226. /// </devdoc>
  227. public int WarningLevel {
  228. get {
  229. return warningLevel;
  230. }
  231. set {
  232. warningLevel = value;
  233. }
  234. }
  235. /// <devdoc>
  236. /// <para>[To be supplied.]</para>
  237. /// </devdoc>
  238. public string CompilerOptions {
  239. get {
  240. return compilerOptions;
  241. }
  242. set {
  243. compilerOptions = value;
  244. }
  245. }
  246. /// <devdoc>
  247. /// <para>[To be supplied.]</para>
  248. /// </devdoc>
  249. public string Win32Resource {
  250. get {
  251. return win32Resource;
  252. }
  253. set {
  254. win32Resource = value;
  255. }
  256. }
  257. /// <devdoc>
  258. /// <para>
  259. /// Gets or sets the resources to be compiled into the target
  260. /// </para>
  261. /// </devdoc>
  262. [ComVisible(false)]
  263. public StringCollection EmbeddedResources {
  264. get {
  265. return embeddedResources;
  266. }
  267. }
  268. /// <devdoc>
  269. /// <para>
  270. /// Gets or sets the linked resources
  271. /// </para>
  272. /// </devdoc>
  273. [ComVisible(false)]
  274. public StringCollection LinkedResources {
  275. get {
  276. return linkedResources;
  277. }
  278. }
  279. /// <devdoc>
  280. /// <para>
  281. /// Gets or sets user token to be employed when creating the compiler process.
  282. /// </para>
  283. /// </devdoc>
  284. public IntPtr UserToken {
  285. get {
  286. #if MONO
  287. return userToken;
  288. #else
  289. if (userToken != null)
  290. return userToken.DangerousGetHandle();
  291. else
  292. return IntPtr.Zero;
  293. #endif
  294. }
  295. set {
  296. #if MONO
  297. userToken = value;
  298. #else
  299. if (userToken != null)
  300. userToken.Close();
  301. userToken = new SafeUserTokenHandle(value, false);
  302. #endif
  303. }
  304. }
  305. #if !MONO
  306. internal SafeUserTokenHandle SafeUserToken {
  307. get {
  308. return userToken;
  309. }
  310. }
  311. #endif
  312. /// <devdoc>
  313. /// <para>
  314. /// Set the evidence for partially trusted scenarios.
  315. /// </para>
  316. /// </devdoc>
  317. [Obsolete("CAS policy is obsolete and will be removed in a future release of the .NET Framework."
  318. + " Please see http://go2.microsoft.com/fwlink/?LinkId=131738 for more information.")]
  319. public Evidence Evidence {
  320. get {
  321. Evidence e = null;
  322. if (evidence != null)
  323. e = evidence.Clone();
  324. return e;
  325. }
  326. [SecurityPermissionAttribute( SecurityAction.Demand, ControlEvidence = true )]
  327. set {
  328. if (value != null)
  329. evidence = value.Clone();
  330. else
  331. evidence = null;
  332. }
  333. }
  334. }
  335. }