Export (0) Print
Expand All

CodeDomProvider.CreateProvider Method (String, IDictionary<String, String>)

Gets a CodeDomProvider instance for the specified language and provider options.

Namespace:  System.CodeDom.Compiler
Assembly:  System (in System.dll)

[ComVisibleAttribute(false)]
public static CodeDomProvider CreateProvider(
	string language,
	IDictionary<string, string> providerOptions
)

Parameters

language
Type: System.String

The language name.

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

A collection of provider options from the configuration file.

Return Value

Type: System.CodeDom.Compiler.CodeDomProvider
A CodeDOM provider that is implemented for the specified language name and options.

NoteNote

This method is most commonly used to create an instance of a code provider in an application that may optionally use one of several providers. CreateProvider(String, IDictionary<String, String>) enables you to specify at run time the version of the code provider you want to instantiate. If you know at design time which code provider is to be used, you should create an instance of that code provider instead of using the CreateProvider(String, IDictionary<String, String>) method.

Use CreateProvider(String, IDictionary<String, String>) when you want to dynamically find a configured provider implementation for a specific language and options. Language names are case-insensitive. For information about supported provider options, see the specific CodeDOM provider documentation.

For information about validating a provider and calling a provider if more than one provider implementation is configured for the language name, see the Remarks section of the CreateProvider(String) method.

The following example shows how to create an instance of a provider by using the providerOptions parameter.

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();
            DisplayVBCompilerInfo();
            Console.WriteLine("Press Enter key to exit.");
            Console.ReadLine();
        }
        static void DisplayCSharpCompilerInfo()
        {
            Dictionary<string, string> provOptions =
            new Dictionary<string, string>();

            provOptions.Add("CompilerVersion", "v4");
            // Get the provider for Microsoft.CSharp
            CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp", provOptions);

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

            Console.WriteLine();
        }

        static void DisplayVBCompilerInfo()
        {
            Dictionary<string, string> provOptions =
            new Dictionary<string, string>();

            provOptions.Add("CompilerVersion", "v3.5");
            // Get the provider for Microsoft.VisualBasic
            CodeDomProvider provider = CodeDomProvider.CreateProvider("VisualBasic", provOptions);

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

            Console.WriteLine();
        }
    }
}

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft