อ่านในภาษาอังกฤษ แก้ไข

แชร์ผ่าน


CompilerInfo.IsCodeDomProviderTypeValid Property

Definition

Returns a value indicating whether the language provider implementation is configured on the computer.

C#
public bool IsCodeDomProviderTypeValid { get; }

Property Value

true if the language provider implementation type is configured on the computer; otherwise, false.

Examples

The following code example determines whether the input language has a configured CodeDomProvider implementation on the computer. If there is a provider configured for the specified language, the example displays the language provider configuration settings. This code example is part of a larger example provided for the CompilerInfo class.

C#
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);
}

Remarks

Use the IsCodeDomProviderTypeValid property to check the CodeDomProvider implementation before accessing the provider properties or methods. For example, after you get the language provider settings from the GetCompilerInfo method, use the IsCodeDomProviderTypeValid property to verify the provider type implementation before calling the CreateProvider method or using the CodeDomProviderType property.

Applies to

ผลิตภัณฑ์ เวอร์ชัน
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also