Partilhar via


CompilerInfo.IsCodeDomProviderTypeValid Propriedade

Definição

Retorna um valor que indica se a implementação de provedor de linguagem de programação está configurada no computador.

public:
 property bool IsCodeDomProviderTypeValid { bool get(); };
public bool IsCodeDomProviderTypeValid { get; }
member this.IsCodeDomProviderTypeValid : bool
Public ReadOnly Property IsCodeDomProviderTypeValid As Boolean

Valor da propriedade

true se o tipo de implementação do provedor de idiomas estiver configurado no computador; caso contrário, false.

Exemplos

O exemplo de código a seguir determina se o idioma de entrada tem uma implementação configurada CodeDomProvider no computador. Se houver um provedor configurado para o idioma especificado, o exemplo exibirá as configurações do provedor de idiomas. Este exemplo de código faz parte de um exemplo maior fornecido para a CompilerInfo classe .

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

Comentários

Use a IsCodeDomProviderTypeValid propriedade para marcar a CodeDomProvider implementação antes de acessar as propriedades ou métodos do provedor. Por exemplo, depois de obter as configurações do provedor de idioma do GetCompilerInfo método , use a IsCodeDomProviderTypeValid propriedade para verificar a implementação do tipo de provedor antes de chamar o CreateProvider método ou usar a CodeDomProviderType propriedade .

Aplica-se a

Confira também