共用方式為


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 從最後一個相符的提供者組態專案傳回設定。

語言名稱不區分大小寫。

適用於

另請參閱