CompilerInfo.GetLanguages Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the language names supported by the language provider.

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

public string[] GetLanguages()

Return Value

Type: System.String[]

An array of language names supported by the language provider.

The <system.codedom> Element in the machine configuration file contains the language provider and compiler configuration settings for each CodeDomProvider implementation on the computer. Each configured language provider supports one or more language names. For example, the CompilerInfo object for a Microsoft.CSharp.CSharpCodeProvider might return an array with the language names "c#", "cs", and "csharp".

The following code example enumerates the language providers on the computer and displays the configuration and compiler settings for each language provider. This code example is part of a larger example provided for the CompilerInfo class.

CompilerInfo [] allCompilerInfo = CodeDomProvider.GetAllCompilerInfo();
foreach (CompilerInfo info in allCompilerInfo)
{
    String defaultLanguage;
    String defaultExtension;

    CodeDomProvider provider = info.CreateProvider();

    // Display information about this configured provider.

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

    Console.WriteLine("  Supported file extension(s):");
    foreach(String extension in info.GetExtensions())
    { 
        Console.WriteLine("    {0}", extension);
    }

    defaultExtension = provider.FileExtension;
    if (defaultExtension[0] != '.')
    {
        defaultExtension = "." + defaultExtension;
    }
    Console.WriteLine("  Default file extension:  {0}", 
        defaultExtension);
    Console.WriteLine();

    Console.WriteLine("  Supported language(s):");
    foreach(String language in info.GetLanguages())
    { 
        Console.WriteLine("    {0}", language);
    }

    defaultLanguage = CodeDomProvider.GetLanguageFromExtension(defaultExtension);
    Console.WriteLine("  Default language:        {0}",
        defaultLanguage);
    Console.WriteLine();

    // Get the compiler settings for this provider.
    CompilerParameters langCompilerConfig = info.CreateDefaultCompilerParameters();

    Console.WriteLine("  Compiler options:        {0}", 
        langCompilerConfig.CompilerOptions);
    Console.WriteLine("  Compiler warning level:  {0}", 
        langCompilerConfig.WarningLevel);
    Console.WriteLine();
}

SecurityPermission

for calling members of CompilerInfo. Demand value: LinkDemand; Associated PermissionState enumeration value: Unrestricted; NIB: Named Permission Sets: FullTrust.

.NET Framework
Available since 2.0
Return to top
Show: