CompilerInfo.CodeDomProviderType 属性

定义

获取已配置的 CodeDomProvider 实现的类型。

public:
 property Type ^ CodeDomProviderType { Type ^ get(); };
public Type CodeDomProviderType { get; }
member this.CodeDomProviderType : Type
Public ReadOnly Property CodeDomProviderType As Type

属性值

一个只读 Type 实例,它表示已配置的语言提供程序类型。

例外

此计算机上没有配置语言提供程序。

不能定位类型,因为它是 null 或空字符串。

- 或 -

不能定位类型,因为不能在配置文件中找到 CodeDomProvider 的名称。

示例

下面的代码示例确定输入语言是否在计算机上配置 CodeDomProvider 了实现。 如果为指定语言配置了提供程序,则本示例显示语言提供程序配置设置。 此代码示例是为 CompilerInfo 类提供的一个更大示例的一部分。

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

注解

计算机配置文件包含计算机上每个 CodeDomProvider 实现的完全限定类型名称。 CodeDomProviderType属性值是表示Type配置的语言提供程序实现的实例。

适用于

另请参阅