Editar

Compartir a través de


CodeDomProvider.GetCompilerInfo(String) Method

Definition

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

Parameters

language
String

A language name.

Returns

A CompilerInfo object populated with settings of the configured CodeDomProvider implementation.

Attributes

Exceptions

The language does not have a configured provider on this computer.

The language is null.

The caller does not have the required permission.

Examples

The following code example determines the CodeDomProvider implementation for an input language and displays the configured settings for the language provider. This 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

Remarks

The <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. The GetCompilerInfo method searches each provider configuration element for the specified language name. The returned CompilerInfo instance contains the configured language provider and compiler settings.

The IsDefinedLanguage method checks whether at least one provider implementation supports a specific language. You can validate a language name using IsDefinedLanguage before passing it to GetCompilerInfo. This prevents throwing a System.Configuration.ConfigurationException when you access the CompilerInfo instance for an unsupported language name.

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.

Applies to

See also