CodeDomProvider.IsDefinedLanguage(String) Méthode

Définition

Vérifie si un langage dispose d'une implémentation de CodeDomProvider configurée sur l'ordinateur.

public:
 static bool IsDefinedLanguage(System::String ^ language);
public static bool IsDefinedLanguage (string language);
[System.Runtime.InteropServices.ComVisible(false)]
public static bool IsDefinedLanguage (string language);
static member IsDefinedLanguage : string -> bool
[<System.Runtime.InteropServices.ComVisible(false)>]
static member IsDefinedLanguage : string -> bool
Public Shared Function IsDefinedLanguage (language As String) As Boolean

Paramètres

language
String

Nom du langage.

Retours

true si une implémentation de CodeDomProvider est configurée pour le langage spécifié ; sinon, false.

Attributs

Exceptions

language a la valeur null.

L'appelant n'a pas l'autorisation requise.

Exemples

L’exemple de code suivant détermine l’implémentation CodeDomProvider d’une langue d’entrée et affiche les paramètres configurés pour le fournisseur de langage. Cet exemple de code fait partie d’un exemple plus grand fourni pour la CompilerInfo classe .

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

Remarques

L’élément< system.codedom> dans le fichier de configuration de l’ordinateur (Machine.config) contient les paramètres de configuration du fournisseur de langage et du compilateur pour chaque CodeDomProvider implémentation sur l’ordinateur. La IsDefinedLanguage méthode recherche le nom de langue spécifié dans les éléments de configuration du fournisseur.

Les noms de langue ne respectent pas la casse.

S’applique à

Voir aussi