CompilerInfo.CreateProvider 方法

定义

返回当前语言提供程序设置的 CodeDomProvider 实例。

重载

CreateProvider()

返回当前语言提供程序设置的 CodeDomProvider 实例。

CreateProvider(IDictionary<String,String>)

返回当前语言提供程序设置和指定选项的 CodeDomProvider 实例。

CreateProvider()

Source:
CompilerInfo.cs
Source:
CompilerInfo.cs
Source:
CompilerInfo.cs

返回当前语言提供程序设置的 CodeDomProvider 实例。

public:
 System::CodeDom::Compiler::CodeDomProvider ^ CreateProvider();
public System.CodeDom.Compiler.CodeDomProvider CreateProvider ();
member this.CreateProvider : unit -> System.CodeDom.Compiler.CodeDomProvider
Public Function CreateProvider () As CodeDomProvider

返回

与语言提供程序配置关联的 CodeDOM 提供程序。

示例

下面的代码示例枚举计算机上的语言提供程序,并显示每个语言提供程序的配置和编译器设置。 此代码示例是为 CompilerInfo 类提供的一个更大示例的一部分。

array<CompilerInfo^>^allCompilerInfo = CodeDomProvider::GetAllCompilerInfo();
for ( int i = 0; i < allCompilerInfo->Length; i++ )
{
   String^ defaultLanguage;
   String^ defaultExtension;
   CompilerInfo^ info = allCompilerInfo[ i ];
   CodeDomProvider^ provider = nullptr;
   if ( info )
      provider = info->CreateProvider();

   if ( provider )
   {
      // Display information about this configured provider.
      Console::WriteLine( "Language provider:  {0}", provider->ToString() );
      Console::WriteLine();
      Console::WriteLine( "  Supported file extension(s):" );
      array<String^>^extensions = info->GetExtensions();
      for ( int i = 0; i < extensions->Length; i++ )
          Console::WriteLine( "    {0}", extensions[ i ] );

      defaultExtension = provider->FileExtension;
      if (  !defaultExtension->StartsWith( "." ) )
          defaultExtension = String::Concat( ".", defaultExtension );

      Console::WriteLine( "  Default file extension:  {0}\n", defaultExtension );
      Console::WriteLine( "  Supported language(s):" );
      array<String^>^languages = info->GetLanguages();
      for ( int i = 0; i < languages->Length; i++ )
          Console::WriteLine( "    {0}", languages[ i ] );

      defaultLanguage = CodeDomProvider::GetLanguageFromExtension( defaultExtension );
      Console::WriteLine(  "  Default language:        {0}", defaultLanguage );
      Console::WriteLine();
      
      // Get the compiler settings for this provider.
      CompilerParameters^ langCompilerConfig = info->CreateDefaultCompilerParameters();
      if ( langCompilerConfig )
      {
         Console::WriteLine( "  Compiler options:        {0}", langCompilerConfig->CompilerOptions );
         Console::WriteLine( "  Compiler warning level:  {0}", langCompilerConfig->WarningLevel.ToString() );
      }
   }

}
CompilerInfo [] allCompilerInfo = CodeDomProvider.GetAllCompilerInfo();
foreach (CompilerInfo info in allCompilerInfo)
{
    String defaultLanguage;
    String defaultExtension;

    CodeDomProvider provider = info.CreateProvider();

    // Display information about this configured provider.

    Console.WriteLine("Language provider:  {0}",
        provider.ToString());
    Console.WriteLine();

    Console.WriteLine("  Supported file extension(s):");
    foreach(String extension in info.GetExtensions())
    {
        Console.WriteLine("    {0}", extension);
    }

    defaultExtension = provider.FileExtension;
    if (defaultExtension[0] != '.')
    {
        defaultExtension = "." + defaultExtension;
    }
    Console.WriteLine("  Default file extension:  {0}",
        defaultExtension);
    Console.WriteLine();

    Console.WriteLine("  Supported language(s):");
    foreach(String language in info.GetLanguages())
    {
        Console.WriteLine("    {0}", language);
    }

    defaultLanguage = CodeDomProvider.GetLanguageFromExtension(defaultExtension);
    Console.WriteLine("  Default language:        {0}",
        defaultLanguage);
    Console.WriteLine();

    // Get the compiler settings for this provider.
    CompilerParameters langCompilerConfig = info.CreateDefaultCompilerParameters();

    Console.WriteLine("  Compiler options:        {0}",
        langCompilerConfig.CompilerOptions);
    Console.WriteLine("  Compiler warning level:  {0}",
        langCompilerConfig.WarningLevel);
    Console.WriteLine();
}
        Dim allCompilerInfo As CompilerInfo() = CodeDomProvider.GetAllCompilerInfo()
        Dim info As CompilerInfo
        For Each info In  allCompilerInfo

           Dim defaultLanguage As String
           Dim defaultExtension As String

           Dim provider As CodeDomProvider = info.CreateProvider()
           
           ' Display information about this configured provider.
           Console.WriteLine("Language provider:  {0}", _
               provider.ToString())
           Console.WriteLine()
           
           Console.WriteLine("  Supported file extension(s):")
           Dim extension As String
           For Each extension In info.GetExtensions()
              Console.WriteLine("    {0}", extension)
           Next extension
           
           defaultExtension = provider.FileExtension
           If Not defaultExtension.StartsWith(".") Then
              defaultExtension = "." + defaultExtension
           End If

           Console.WriteLine("  Default file extension:  {0}", _
             defaultExtension)
           Console.WriteLine()
           
           Console.WriteLine("  Supported language(s):")
           Dim language As String
           For Each language In  info.GetLanguages()
              Console.WriteLine("    {0}", language)
           Next language
           defaultLanguage = CodeDomProvider.GetLanguageFromExtension(defaultExtension)
           Console.WriteLine("  Default language:        {0}", _
              defaultLanguage)
           Console.WriteLine()
           
           ' Get the compiler settings for this provider.
           Dim langCompilerConfig As CompilerParameters = info.CreateDefaultCompilerParameters()
           
           Console.WriteLine("  Compiler options:        {0}", _
               langCompilerConfig.CompilerOptions)
           Console.WriteLine("  Compiler warning level:  {0}", _
               langCompilerConfig.WarningLevel)
           Console.WriteLine()
        Next info

注解

方法 CreateProvider 返回 CodeDomProvider 当前语言提供程序设置的实例。

CreateProvider使用 方法获取 CodeDomProviderCodeDomProvider.GetCompilerInfo 方法返回的CompilerInfo实例的CodeDomProvider.GetAllCompilerInfo实现。

另请参阅

适用于

CreateProvider(IDictionary<String,String>)

Source:
CompilerInfo.cs
Source:
CompilerInfo.cs
Source:
CompilerInfo.cs

返回当前语言提供程序设置和指定选项的 CodeDomProvider 实例。

public:
 System::CodeDom::Compiler::CodeDomProvider ^ CreateProvider(System::Collections::Generic::IDictionary<System::String ^, System::String ^> ^ providerOptions);
public System.CodeDom.Compiler.CodeDomProvider CreateProvider (System.Collections.Generic.IDictionary<string,string> providerOptions);
member this.CreateProvider : System.Collections.Generic.IDictionary<string, string> -> System.CodeDom.Compiler.CodeDomProvider
Public Function CreateProvider (providerOptions As IDictionary(Of String, String)) As CodeDomProvider

参数

providerOptions
IDictionary<String,String>

来自配置文件的提供程序选项的集合。

返回

与语言提供程序配置和指定选项关联的 CodeDOM 提供程序。

例外

providerOptionsnull

提供程序不支持选项。

注解

方法 CreateProvider(IDictionary<String,String>) 返回 CodeDomProvider 当前语言提供程序设置和指定提供程序选项的实例。 有关支持的提供程序选项的信息,请参阅特定的 CodeDOM 提供程序文档。

CreateProvider(IDictionary<String,String>)使用 方法获取 CodeDomProviderCodeDomProvider.GetCompilerInfo 方法返回的CompilerInfo实例的CodeDomProvider.GetAllCompilerInfo实现。

适用于