Επεξεργασία

Κοινή χρήση μέσω


CompilerInfo.CreateDefaultCompilerParameters Method

Definition

Gets the configured compiler settings for the language provider implementation.

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

Returns

A read-only CompilerParameters instance that contains the compiler options and settings configured for the language provider.

Examples

The following code example determines whether the input language has a configured CodeDomProvider implementation on the computer. If there is a provider configured for the specified language, the example displays the language provider configuration settings. This code example is part of a larger example provided for the CompilerInfo class.

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

Remarks

Use the CreateDefaultCompilerParameters method to examine the compiler settings of the CompilerInfo instances returned by the CodeDomProvider.GetAllCompilerInfo and CodeDomProvider.GetCompilerInfo methods.

The <system.codedom> Element in the machine configuration file contains the language provider and compiler configuration settings for each CodeDomProvider implementation on the computer. Each language provider configuration element can contain optional compilerOptions and warningLevel attributes. These attributes define the default values for the CompilerParameters.CompilerOptions and CompilerParameters.WarningLevel properties.

If the language provider configuration element does not define the compilerOptions attribute, the CompilerParameters.CompilerOptions property value is an empty string (""). If the language provider configuration element does not define the warningLevel attribute, the CompilerParameters.WarningLevel property value is -1.

Applies to

See also