Costruttore CSharpCodeProvider (IDictionary<String, String>)

 

Data di pubblicazione: novembre 2016

Inizializza una nuova istanza della classe CSharpCodeProvider tramite le opzioni del provider specificate.

Spazio dei nomi:   Microsoft.CSharp
Assembly:  System (in System.dll)

public CSharpCodeProvider(
	IDictionary<string, string> providerOptions
)

Parametri

providerOptions
Type: System.Collections.Generic.IDictionary<String, String>

Oggetto IDictionary<TKey, TValue> che contiene le opzioni del provider del file di configurazione.

Exception Condition
ArgumentNullException

providerOptions è null.

The value for providerOptions is obtained from the element in the configuration file. You can identify the version of the T:Microsoft.CSharp.CSharpCodeProvider you want to use by specifying the <providerOption> element, supplying "CompilerVersion" as the option name, and supplying the version number (for example, "v3.5") as the option value. You must precede the version number with a lower case "v".

The following configuration file example demonstrates how to specify that version 3.5 of the C# code provider should be used.

<configuration>
  <system.codedom>
    <compilers>
      <!-- zero or more compiler elements -->
      <compiler
        language="c#;cs;csharp"
        extension=".cs"
        type="Microsoft.CSharp.CSharpCodeProvider, System, 
          Version=2.0.3600.0, Culture=neutral, 
          PublicKeyToken=b77a5c561934e089"
        compilerOptions="/optimize"
        warningLevel="1" >
          <providerOption
            name="CompilerVersion"
            value="v3.5" />
      </compiler>
    </compilers>
  </system.codedom>
</configuration>

The following example shows how to specify the compiler version when you create a new instance of the T:Microsoft.CSharp.CSharpCodeProvider class.

using System;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using System.Collections.Generic;

namespace ProviderOptions
{
    class Program
    {
        static void Main(string[] args)
        {
            DisplayCSharpCompilerInfo();
            Console.WriteLine("Press Enter key to exit.");
            Console.ReadLine();
        }
        static void DisplayCSharpCompilerInfo()
        {
            Dictionary<string, string> provOptions =
            new Dictionary<string, string>();

            provOptions.Add("CompilerVersion", "v3.5");
            // Get the provider for Microsoft.CSharp
            CSharpCodeProvider csProvider = new CSharpCodeProvider(provOptions);

            // Display the C# language provider information.
            Console.WriteLine("CSharp provider is {0}",
                csProvider.ToString());
            Console.WriteLine("  Provider hash code:     {0}",
                csProvider.GetHashCode().ToString());
            Console.WriteLine("  Default file extension: {0}",
                csProvider.FileExtension);

            Console.WriteLine();
        }


    }
}

LinkDemand

for full trust for the immediate caller. This member cannot be used by partially trusted code.

.NET Framework
Disponibile da 2.0
Torna all'inizio
Mostra: