CodeDomProvider.GetCompilerInfo(String) 方法

定义

返回指定语言的语言提供程序和编译器配置设置。

public:
 static System::CodeDom::Compiler::CompilerInfo ^ GetCompilerInfo(System::String ^ language);
public static System.CodeDom.Compiler.CompilerInfo GetCompilerInfo (string language);
[System.Runtime.InteropServices.ComVisible(false)]
public static System.CodeDom.Compiler.CompilerInfo GetCompilerInfo (string language);
static member GetCompilerInfo : string -> System.CodeDom.Compiler.CompilerInfo
[<System.Runtime.InteropServices.ComVisible(false)>]
static member GetCompilerInfo : string -> System.CodeDom.Compiler.CompilerInfo
Public Shared Function GetCompilerInfo (language As String) As CompilerInfo

参数

language
String

语言名称。

返回

一个 CompilerInfo 对象,由已配置的 CodeDomProvider 实现的设置填充。

属性

例外

language 在此计算机上没有已配置的提供程序。

languagenull

调用方没有所要求的权限。

示例

下面的代码示例确定输入语言的 CodeDomProvider 实现,并显示语言提供程序的配置设置。 此代码示例是为 CompilerInfo 类提供的一个更大示例的一部分。

CodeDomProvider^ provider = nullptr;

// Check for a provider corresponding to the input language.  
if ( CodeDomProvider::IsDefinedLanguage( language ) )
{
   provider = CodeDomProvider::CreateProvider( language );
   if ( provider )
   {
      // Display information about this language provider.
      Console::WriteLine( "Language provider:  {0}", provider->ToString() );
      Console::WriteLine();
      Console::WriteLine( "  Default file extension:  {0}", provider->FileExtension );
      Console::WriteLine();
      
      // Get the compiler settings for this language.
      CompilerInfo^ langCompilerInfo = CodeDomProvider::GetCompilerInfo( language );
      if ( langCompilerInfo )
      {
         CompilerParameters^ langCompilerConfig = langCompilerInfo->CreateDefaultCompilerParameters();
         if ( langCompilerConfig )
         {
            Console::WriteLine( "  Compiler options:        {0}", langCompilerConfig->CompilerOptions );
            Console::WriteLine( "  Compiler warning level:  {0}", langCompilerConfig->WarningLevel.ToString() );
         }
      }
   }
}

if ( provider == nullptr )  // Tell the user that the language provider was not found.
   Console::WriteLine(  "There is no provider configured for input language \"{0}\".", language );
CodeDomProvider provider;

// Check for a provider corresponding to the input language.
if (CodeDomProvider.IsDefinedLanguage(language))
{
    provider = CodeDomProvider.CreateProvider(language);

    // Display information about this language provider.

    Console.WriteLine("Language provider:  {0}",
        provider.ToString());
    Console.WriteLine();
    Console.WriteLine("  Default file extension:  {0}",
        provider.FileExtension);
    Console.WriteLine();

    // Get the compiler settings for this language.

    CompilerInfo langCompilerInfo = CodeDomProvider.GetCompilerInfo(language);
    CompilerParameters langCompilerConfig = langCompilerInfo.CreateDefaultCompilerParameters();

    Console.WriteLine("  Compiler options:        {0}",
        langCompilerConfig.CompilerOptions);
    Console.WriteLine("  Compiler warning level:  {0}",
        langCompilerConfig.WarningLevel);
}
else
{
    // Tell the user that the language provider was not found.
    Console.WriteLine("There is no provider configured for input language \"{0}\".",
        language);
}
Dim provider As CodeDomProvider

' Check for a provider corresponding to the input language.  
If CodeDomProvider.IsDefinedLanguage(language) Then
   provider = CodeDomProvider.CreateProvider(language)
   
   ' Display information about this language provider.
   Console.WriteLine("Language provider:  {0}", _
       provider.ToString())
   Console.WriteLine()
   Console.WriteLine("  Default file extension:  {0}", _
       provider.FileExtension)
   Console.WriteLine()
   
   ' Get the compiler settings for this language.
   Dim langCompilerInfo As CompilerInfo = CodeDomProvider.GetCompilerInfo(language)
   Dim langCompilerConfig As CompilerParameters = langCompilerInfo.CreateDefaultCompilerParameters()
   
   Console.WriteLine("  Compiler options:        {0}", _
       langCompilerConfig.CompilerOptions)
   Console.WriteLine("  Compiler warning level:  {0}", _
       langCompilerConfig.WarningLevel)
Else
   ' Tell the user that the language provider was not found.
   Console.WriteLine("There is no provider configured for input language ""{0}"".", _
       language)
End If

注解

计算机配置文件中的 system.codedom> 元素包含计算机上每个实现的语言提供程序和编译器配置设置。<CodeDomProvider 有关计算机配置文件的信息,请参阅 配置应用中的计算机配置文件部分。 方法 GetCompilerInfo 在每个提供程序配置元素中搜索指定的语言名称。 返回的 CompilerInfo 实例包含配置的语言提供程序和编译器设置。

方法 IsDefinedLanguage 检查是否至少有一个提供程序实现支持特定语言。 在将语言名称传递给 之前,可以使用 验证语言GetCompilerInfo名称IsDefinedLanguage。 这可以防止在访问CompilerInfo实例时引发 System.Configuration.ConfigurationException 不受支持的语言名称。

如果为输入语言名称配置了多个提供程序实现, GetCompilerInfo 则从最后一个匹配的提供程序配置元素返回设置。

语言名称不区分大小写。

适用于

另请参阅