The Labs \ Source Viewer \ SSCLI \ System.CodeDom.Compiler \ CompilerParameters

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CompilerParameters.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.CodeDom.Compiler
  16. {
  17.     using System;
  18.     using System.CodeDom;
  19.     using System.Collections;
  20.     using System.Collections.Specialized;
  21.     using Microsoft.Win32;
  22.     using Microsoft.Win32.SafeHandles;
  23.     using System.Runtime.InteropServices;
  24.     using System.Security.Permissions;
  25.     using System.Security.Policy;
  26.     using System.Runtime.Serialization;
  27.    
  28.     /// <devdoc>
  29.     /// <para>
  30.     /// Represents the parameters used in to invoke the compiler.
  31.     /// </para>
  32.     /// </devdoc>
  33.     [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
  34.     [PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
  35.     [Serializable()]
  36.     public class CompilerParameters
  37.     {
  38.         private StringCollection assemblyNames = new StringCollection();
  39.        
  40.         [OptionalField()]
  41.         private StringCollection embeddedResources = new StringCollection();
  42.         [OptionalField()]
  43.         private StringCollection linkedResources = new StringCollection();
  44.        
  45.         private string outputName;
  46.         private string mainClass;
  47.         private bool generateInMemory = false;
  48.         private bool includeDebugInformation = false;
  49.         private int warningLevel = -1;
  50.         // -1 means not set (use compiler default)
  51.         private string compilerOptions;
  52.         private string win32Resource;
  53.         private bool treatWarningsAsErrors = false;
  54.         private bool generateExecutable = false;
  55.         private TempFileCollection tempFiles;
  56.         [NonSerializedAttribute()]
  57.         private SafeUserTokenHandle userToken;
  58.         private Evidence evidence = null;
  59.        
  60.         /// <devdoc>
  61.         /// <para>
  62.         /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerParameters'/>.
  63.         /// </para>
  64.         /// </devdoc>
  65.         public CompilerParameters() : this(null, null)
  66.         {
  67.         }
  68.        
  69.         /// <devdoc>
  70.         /// <para>
  71.         /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerParameters'/> using the specified
  72.         /// assembly names.
  73.         /// </para>
  74.         /// </devdoc>
  75.         public CompilerParameters(string[] assemblyNames) : this(assemblyNames, null, false)
  76.         {
  77.         }
  78.        
  79.         /// <devdoc>
  80.         /// <para>
  81.         /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerParameters'/> using the specified
  82.         /// assembly names and output name.
  83.         /// </para>
  84.         /// </devdoc>
  85.         public CompilerParameters(string[] assemblyNames, string outputName) : this(assemblyNames, outputName, false)
  86.         {
  87.         }
  88.        
  89.         /// <devdoc>
  90.         /// <para>
  91.         /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerParameters'/> using the specified
  92.         /// assembly names, output name and a whether to include debug information flag.
  93.         /// </para>
  94.         /// </devdoc>
  95.         public CompilerParameters(string[] assemblyNames, string outputName, bool includeDebugInformation)
  96.         {
  97.             if (assemblyNames != null) {
  98.                 ReferencedAssemblies.AddRange(assemblyNames);
  99.             }
  100.             this.outputName = outputName;
  101.             this.includeDebugInformation = includeDebugInformation;
  102.         }
  103.        
  104.         /// <devdoc>
  105.         /// <para>
  106.         /// Gets or sets whether to generate an executable.
  107.         /// </para>
  108.         /// </devdoc>
  109.         public bool GenerateExecutable {
  110.             get { return generateExecutable; }
  111.             set { generateExecutable = value; }
  112.         }
  113.        
  114.         /// <devdoc>
  115.         /// <para>
  116.         /// Gets or sets whether to generate in memory.
  117.         /// </para>
  118.         /// </devdoc>
  119.         public bool GenerateInMemory {
  120.             get { return generateInMemory; }
  121.             set { generateInMemory = value; }
  122.         }
  123.        
  124.         /// <devdoc>
  125.         /// <para>
  126.         /// Gets or sets the assemblies referenced by the source to compile.
  127.         /// </para>
  128.         /// </devdoc>
  129.         public StringCollection ReferencedAssemblies {
  130.             get { return assemblyNames; }
  131.         }
  132.        
  133.         /// <devdoc>
  134.         /// <para>
  135.         /// Gets or sets the main class.
  136.         /// </para>
  137.         /// </devdoc>
  138.         public string MainClass {
  139.             get { return mainClass; }
  140.             set { mainClass = value; }
  141.         }
  142.        
  143.         /// <devdoc>
  144.         /// <para>
  145.         /// Gets or sets the output assembly.
  146.         /// </para>
  147.         /// </devdoc>
  148.         public string OutputAssembly {
  149.             get { return outputName; }
  150.             set { outputName = value; }
  151.         }
  152.        
  153.         /// <devdoc>
  154.         /// <para>
  155.         /// Gets or sets the temp files.
  156.         /// </para>
  157.         /// </devdoc>
  158.         public TempFileCollection TempFiles {
  159.             get {
  160.                 if (tempFiles == null)
  161.                     tempFiles = new TempFileCollection();
  162.                 return tempFiles;
  163.             }
  164.             set { tempFiles = value; }
  165.         }
  166.        
  167.         /// <devdoc>
  168.         /// <para>
  169.         /// Gets or sets whether to include debug information in the compiled
  170.         /// executable.
  171.         /// </para>
  172.         /// </devdoc>
  173.         public bool IncludeDebugInformation {
  174.             get { return includeDebugInformation; }
  175.             set { includeDebugInformation = value; }
  176.         }
  177.        
  178.         /// <devdoc>
  179.         /// <para>[To be supplied.]</para>
  180.         /// </devdoc>
  181.         public bool TreatWarningsAsErrors {
  182.             get { return treatWarningsAsErrors; }
  183.             set { treatWarningsAsErrors = value; }
  184.         }
  185.        
  186.         /// <devdoc>
  187.         /// <para>[To be supplied.]</para>
  188.         /// </devdoc>
  189.         public int WarningLevel {
  190.             get { return warningLevel; }
  191.             set { warningLevel = value; }
  192.         }
  193.        
  194.         /// <devdoc>
  195.         /// <para>[To be supplied.]</para>
  196.         /// </devdoc>
  197.         public string CompilerOptions {
  198.             get { return compilerOptions; }
  199.             set { compilerOptions = value; }
  200.         }
  201.        
  202.         /// <devdoc>
  203.         /// <para>[To be supplied.]</para>
  204.         /// </devdoc>
  205.         public string Win32Resource {
  206.             get { return win32Resource; }
  207.             set { win32Resource = value; }
  208.         }
  209.        
  210.         /// <devdoc>
  211.         /// <para>
  212.         /// Gets or sets the resources to be compiled into the target
  213.         /// </para>
  214.         /// </devdoc>
  215.         [System.Runtime.InteropServices.ComVisible(false)]
  216.         public StringCollection EmbeddedResources {
  217.             get { return embeddedResources; }
  218.         }
  219.        
  220.         /// <devdoc>
  221.         /// <para>
  222.         /// Gets or sets the linked resources
  223.         /// </para>
  224.         /// </devdoc>
  225.         [System.Runtime.InteropServices.ComVisible(false)]
  226.         public StringCollection LinkedResources {
  227.             get { return linkedResources; }
  228.         }
  229.        
  230.         /// <devdoc>
  231.         /// <para>
  232.         /// Gets or sets user token to be employed when creating the compiler process.
  233.         /// </para>
  234.         /// </devdoc>
  235.         public IntPtr UserToken {
  236.             get {
  237.                 if (userToken != null)
  238.                     return userToken.DangerousGetHandle();
  239.                 else
  240.                     return IntPtr.Zero;
  241.             }
  242.             set {
  243.                 if (userToken != null)
  244.                     userToken.Close();
  245.                
  246.                 userToken = new SafeUserTokenHandle(value, false);
  247.             }
  248.         }
  249.        
  250.         internal SafeUserTokenHandle SafeUserToken {
  251.             get { return userToken; }
  252.         }
  253.        
  254.         /// <devdoc>
  255.         /// <para>
  256.         /// Set the evidence for partially trusted scenarios.
  257.         /// </para>
  258.         /// </devdoc>
  259.         public Evidence Evidence {
  260.             get {
  261.                 Evidence e = null;
  262.                 if (evidence != null)
  263.                     e = CompilerResults.CloneEvidence(evidence);
  264.                 return e;
  265.             }
  266.             [SecurityPermissionAttribute(SecurityAction.Demand, ControlEvidence = true)]
  267.             set {
  268.                 if (value != null)
  269.                     evidence = CompilerResults.CloneEvidence(value);
  270.                 else
  271.                     evidence = null;
  272.             }
  273.         }
  274.     }
  275. }

Developer Fusion