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.GetAllCompilerInfoCompilerInfo实例的编译器设置。

计算机配置文件中的 system.codedom> 元素包含计算机上每个实现的语言提供程序和编译器配置设置。<CodeDomProvider 每个语言提供程序配置元素都可以包含可选的 compilerOptionswarningLevel 属性。 这些属性定义 和 CompilerParameters.WarningLevel 属性的CompilerParameters.CompilerOptions默认值。

如果语言提供程序配置元素未定义 compilerOptions 属性,则 CompilerParameters.CompilerOptions 属性值为空字符串 (“”) 。 如果语言提供程序配置元素未定义 warningLevel 属性,则 CompilerParameters.WarningLevel 属性值为 -1。

适用于

另请参阅