Redigera

Dela via


CSharpCodeProvider Constructors

Definition

Initializes a new instance of the CSharpCodeProvider class.

Overloads

CSharpCodeProvider()

Initializes a new instance of the CSharpCodeProvider class.

CSharpCodeProvider(IDictionary<String,String>)

Initializes a new instance of the CSharpCodeProvider class by using the specified provider options.

CSharpCodeProvider()

Source:
CSharpCodeProvider.cs
Source:
CSharpCodeProvider.cs
Source:
CSharpCodeProvider.cs
Source:
CSharpCodeProvider.cs

Initializes a new instance of the CSharpCodeProvider class.

public:
 CSharpCodeProvider();
public CSharpCodeProvider ();
Public Sub New ()

Applies to

CSharpCodeProvider(IDictionary<String,String>)

Source:
CSharpCodeProvider.cs
Source:
CSharpCodeProvider.cs
Source:
CSharpCodeProvider.cs
Source:
CSharpCodeProvider.cs

Initializes a new instance of the CSharpCodeProvider class by using the specified provider options.

public:
 CSharpCodeProvider(System::Collections::Generic::IDictionary<System::String ^, System::String ^> ^ providerOptions);
public CSharpCodeProvider (System.Collections.Generic.IDictionary<string,string> providerOptions);
new Microsoft.CSharp.CSharpCodeProvider : System.Collections.Generic.IDictionary<string, string> -> Microsoft.CSharp.CSharpCodeProvider
Public Sub New (providerOptions As IDictionary(Of String, String))

Parameters

providerOptions
IDictionary<String,String>

A IDictionary<TKey,TValue> object that contains the provider options.

Exceptions

providerOptions is null.

Examples

The following example shows how to specify the compiler version when you create a new instance of the 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();
        }
    }
}

Remarks

In .NET Framework apps, you can obtain the value for providerOptions from the <providerOption> element in the configuration file. You can identify the version of the 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>

See also

Applies to