CodeDomProvider.IsDefinedLanguage(String) 方法

定义

测试某语言是否已在计算机上配置了 CodeDomProvider 实现。Tests whether a language has a CodeDomProvider implementation configured on the computer.

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

参数

language
String

语言名称。The language name.

返回

Boolean

如果为指定语言配置了 CodeDomProvider 实现,则为 true;否则,为 falsetrue if a CodeDomProvider implementation is configured for the specified language; otherwise, false.

属性

例外

languagenullThe language is null.

调用方没有所要求的权限。The caller does not have the required permission.

示例

下面的代码示例确定 CodeDomProvider 输入语言的实现,并显示语言提供程序的配置设置。The following code example determines the CodeDomProvider implementation for an input language and displays the configured settings for the language provider. 此代码示例是为类提供的更大示例的一部分 CompilerInfoThis 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

注解

计算机配置文件中的 < system.object > 元素 (Machine.config) 包含计算机上每个实现的语言提供程序和编译器配置设置 CodeDomProviderThe <system.codedom> Element in the machine configuration file (Machine.config) contains the language provider and compiler configuration settings for each CodeDomProvider implementation on the computer. IsDefinedLanguage方法在提供程序配置元素中搜索指定的语言名称。The IsDefinedLanguage method searches the provider configuration elements for the specified language name.

语言名称不区分大小写。Language names are case-insensitive.

适用于

另请参阅