共用方式為


CompilerInfo.CreateDefaultCompilerParameters 方法

定義

取得語言提供者實作的已設定編譯器設定。

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

傳回

唯讀的 CompilerParameters 執行個體,該執行個體包含已經為語言提供者設定的編譯器選項和設定。

範例

下列程式代碼範例會判斷輸入語言是否在計算機上具有已設定 CodeDomProvider 的實作。 如果有針對指定語言設定的提供者,此範例會顯示語言提供者組態設定。 此程式代碼範例是提供給 類別之較大範例的 CompilerInfo 一部分。

CodeDomProvider^ provider = nullptr;
CompilerInfo^ info = CodeDomProvider::GetCompilerInfo( configLanguage );

// Check whether there is a provider configured for this language.
if ( info->IsCodeDomProviderTypeValid )
{
   // Get a provider instance using the configured type information.
   provider = dynamic_cast<CodeDomProvider^>(Activator::CreateInstance( info->CodeDomProviderType ));
   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.
      CompilerParameters^ langCompilerConfig = info->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}\".", configLanguage );
CompilerInfo info = CodeDomProvider.GetCompilerInfo(configLanguage);

// Check whether there is a provider configured for this language.
if (info.IsCodeDomProviderTypeValid)
{
    // Get a provider instance using the configured type information.
    CodeDomProvider provider;
    provider = (CodeDomProvider)Activator.CreateInstance(info.CodeDomProviderType);

    // 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.

    CompilerParameters langCompilerConfig = info.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}\".",
        configLanguage);
}
Dim info As CompilerInfo = CodeDomProvider.GetCompilerInfo(configLanguage)

' Check whether there is a provider configured for this language.
If info.IsCodeDomProviderTypeValid Then
   ' Get a provider instance using the configured type information.
   Dim provider As CodeDomProvider
   provider = CType(Activator.CreateInstance(info.CodeDomProviderType), CodeDomProvider)
   
   ' 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 langCompilerConfig As CompilerParameters = info.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}"".", configLanguage)
End If

備註

CreateDefaultCompilerParameters使用方法來檢查 和 CodeDomProvider.GetCompilerInfo 方法所CodeDomProvider.GetAllCompilerInfo傳回之實例的CompilerInfo編譯程序設定。

電腦組態檔中的 system.codedom> 元素包含電腦上每個實作的語言提供者和編譯程式組態設定。<CodeDomProvider 每個語言提供者組態專案都可以包含選擇性 compilerOptionswarningLevel 屬性。 這些屬性會定義 和 CompilerParameters.WarningLevel 屬性的CompilerParameters.CompilerOptions預設值。

如果語言提供者組態專案未定義 compilerOptions 屬性, CompilerParameters.CompilerOptions 屬性值會是空字串 (“”) 。 如果語言提供者組態專案未定義 warningLevel 屬性, CompilerParameters.WarningLevel 則屬性值為 -1。

適用於

另請參閱