CodeDomProvider.GetCompilerInfo(String) 方法

定义

返回指定语言的语言提供程序和编译器配置设置。Returns the language provider and compiler configuration settings for the specified language.

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

语言名称。A language name.

返回

CompilerInfo

一个 CompilerInfo 对象,由已配置的 CodeDomProvider 实现的设置填充。A CompilerInfo object populated with settings of the configured CodeDomProvider implementation.

属性

例外

language 在此计算机上没有已配置的提供程序。The language does not have a configured provider on this computer.

languagenullThe language is null.

调用方没有所要求的权限。The caller does not have the required permission.

示例

下面的代码示例确定 CodeDomProvider 输入语言的实现,并显示语言提供程序的配置设置。The following code example determines the CodeDomProvider implementation for an input language and displays the configured settings for the language provider. 此代码示例是为类提供的更大示例的一部分 CompilerInfoThis code example is part of a larger example provided for the CompilerInfo class.

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.object > 元素包含计算机上每个实现的语言提供程序和编译器配置设置 CodeDomProviderThe <system.codedom> Element in the machine configuration file contains the language provider and compiler configuration settings for each CodeDomProvider implementation on the computer. 有关计算机配置文件的信息,请参阅 配置应用中的计算机配置文件部分。For information about machine configuration files, see the Machine Configuration Files section in Configuring Apps. GetCompilerInfo方法搜索指定语言名称的每个提供程序配置元素。The GetCompilerInfo method searches each provider configuration element for the specified language name. 返回 CompilerInfo 的实例包含已配置的语言提供程序和编译器设置。The returned CompilerInfo instance contains the configured language provider and compiler settings.

IsDefinedLanguage方法检查是否至少有一个提供程序实现支持特定语言。The IsDefinedLanguage method checks whether at least one provider implementation supports a specific language. 在将语言名称传递给之前,可以使用对 IsDefinedLanguage 其进行验证 GetCompilerInfoYou can validate a language name using IsDefinedLanguage before passing it to GetCompilerInfo. 这会阻止在 System.Configuration.ConfigurationException 访问 CompilerInfo 不受支持的语言名称的实例时引发。This prevents throwing a System.Configuration.ConfigurationException when you access the CompilerInfo instance for an unsupported language name.

如果为输入语言名称配置了多个提供程序实现,则将 GetCompilerInfo 返回最后一个匹配提供程序配置元素中的设置。If more than one provider implementation is configured for the input language name, GetCompilerInfo returns the settings from the last matching provider configuration element.

语言名称不区分大小写。Language names are case-insensitive.

适用于

另请参阅