Export (0) Print
Expand All

CodeDomProvider.IsDefinedExtension Method

Tests whether a file name extension has an associated CodeDomProvider implementation configured on the computer.

Namespace:  System.CodeDom.Compiler
Assembly:  System (in System.dll)

public static bool IsDefinedExtension(
	string extension


Type: System.String

A file name extension.

Return Value

Type: System.Boolean
true if a CodeDomProvider implementation is configured for the specified file name extension; otherwise, false.


The extension is null.


The caller does not have the required permission.

The <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. The IsDefinedExtension method searches the provider configuration elements for the specified file name extension.

File name extensions are case-insensitive.

The following code example determines the CodeDomProvider implementation for an input file name extension and displays the configured settings for the language provider. This code example is part of a larger example provided for the CompilerInfo class.

if (fileExtension[0] != '.')
    fileExtension = "." + fileExtension;

// Get the language associated with the file extension. 
if (CodeDomProvider.IsDefinedExtension(fileExtension))
    CodeDomProvider provider;
    String language = CodeDomProvider.GetLanguageFromExtension(fileExtension);

    Console.WriteLine("The language \"{0}\" is associated with file extension \"{1}\"", 
        language, fileExtension);

    // Next, check for a corresponding language provider. 

    if (CodeDomProvider.IsDefinedLanguage(language))
        provider = CodeDomProvider.CreateProvider(language);

        // Display information about this language provider.

        Console.WriteLine("Language provider:  {0}", 

        // Get the compiler settings for this language.

        CompilerInfo langCompilerInfo = CodeDomProvider.GetCompilerInfo(language);
        CompilerParameters langCompilerConfig = langCompilerInfo.CreateDefaultCompilerParameters();

        Console.WriteLine("  Compiler options:        {0}", 
        Console.WriteLine("  Compiler warning level:  {0}", 
    // Tell the user that the language provider was not found.
    Console.WriteLine("There is no language provider associated with input file extension \"{0}\".", 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft