다음을 통해 공유


CompilerInfo 클래스

정의

언어 공급자의 구성 설정을 나타냅니다. 이 클래스는 상속될 수 없습니다.

public ref class CompilerInfo sealed
public sealed class CompilerInfo
type CompilerInfo = class
Public NotInheritable Class CompilerInfo
상속
CompilerInfo

예제

다음 코드 예제에서는 언어 공급자 구성 설정을 표시합니다. 명령줄 인수는 언어, 파일 이름 확장명 또는 공급자 형식을 지정하는 데 사용됩니다. 지정된 입력의 경우 예제는 해당 언어 공급자를 결정하고 구성된 언어 컴파일러 설정을 표시합니다.

// Command-line argument examples:
//      - Displays Visual Basic, C#, and JScript compiler settings.
//   <exe_name> Language CSharp
//      - Displays the compiler settings for C#.
//   <exe_name> All
//      - Displays settings for all configured compilers.
//   <exe_name> Config Pascal
//      - Displays settings for configured Pascal language provider,
//        if one exists.
//   <exe_name> Extension .vb
//      - Displays settings for the compiler associated with the .vb
//        file extension.
#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Globalization;
using namespace System::CodeDom;
using namespace System::CodeDom::Compiler;
using namespace Microsoft::CSharp;
using namespace Microsoft::VisualBasic;
using namespace System::Configuration;
using namespace System::Security::Permissions;

namespace CodeDomCompilerInfoSample
{
   [PermissionSet(SecurityAction::Demand, Name="FullTrust")]
   public ref class CompilerInfoSample
   {
   public:
      static void Main( array<String^>^args )
      {
         String^ queryCommand = "";
         String^ queryArg = "";
         int iNumArguments = args->Length;
         
         // Get input command-line arguments.
         if ( iNumArguments > 0 )
         {
            queryCommand = args[ 0 ]->ToUpper( CultureInfo::InvariantCulture );
            if ( iNumArguments > 1 )
               queryArg = args[ 1 ];
         }

         // Determine which method to call.
         Console::WriteLine();
         if ( queryCommand->Equals( "LANGUAGE" ) )
             DisplayCompilerInfoForLanguage( queryArg );        // Display compiler information for input language.
         else if ( queryCommand->Equals( "EXTENSION" ) )
             DisplayCompilerInfoUsingExtension( queryArg );     // Display compiler information for input file extension.
         else if ( queryCommand->Equals( "CONFIG" ) )
             DisplayCompilerInfoForConfigLanguage( queryArg );  // Display settings for the configured language provider.
         else if ( queryCommand->Equals( "ALL" ) )
             DisplayAllCompilerInfo();             // Display compiler information for all configured language providers.
         else
         {
            // There was no command-line argument, or the 
            // command-line argument was not recognized.
            // Display the C#, Visual Basic and JScript 
            // compiler information.
            DisplayCSharpCompilerInfo();
            DisplayVBCompilerInfo();
            DisplayJScriptCompilerInfo();
         }
      }


   private:
      static void DisplayCSharpCompilerInfo()
      {
         // Get the provider for Microsoft.CSharp
//         CodeDomProvider^ provider = CodeDomProvider.CreateProvider("CSharp");
         CodeDomProvider^ provider = CodeDomProvider::CreateProvider("CSharp");

         if ( provider )
         {
            // Display the C# language provider information.
            Console::WriteLine( "CSharp provider is {0}", provider->ToString() );
            Console::WriteLine( "  Provider hash code:     {0}", provider->GetHashCode().ToString() );
            Console::WriteLine( "  Default file extension: {0}", provider->FileExtension );
         }

         Console::WriteLine();
      }

      static void DisplayVBCompilerInfo()
      {
         // Get the provider for Microsoft.VisualBasic
//         CodeDomProvider^ provider = CodeDomProvider.CreateProvider("VisualBasic");
         CodeDomProvider^ provider = CodeDomProvider::CreateProvider("VisualBasic");
         if ( provider ) // Display the Visual Basic language provider information.
         {
            Console::WriteLine( "Visual Basic provider is {0}", provider->ToString() );
            Console::WriteLine( "  Provider hash code:     {0}", provider->GetHashCode().ToString() );
            Console::WriteLine( "  Default file extension: {0}", provider->FileExtension );
         }

         Console::WriteLine();
      }

      static void DisplayJScriptCompilerInfo()
      {
         // Get the provider for JScript.
         CodeDomProvider^ provider;
         try
         {
//            provider = CodeDomProvider.CreateProvider("JScript");
            provider = CodeDomProvider::CreateProvider("JScript");
            if ( provider )
            {
               // Display the JScript language provider information.
               Console::WriteLine( "JScript language provider is {0}", provider->ToString() );
               Console::WriteLine( "  Provider hash code:     {0}", provider->GetHashCode().ToString() );
               Console::WriteLine( "  Default file extension: {0}", provider->FileExtension );
               Console::WriteLine();
            }
         }
         catch ( ConfigurationException^ e ) 
         {
            // The JScript language provider was not found.
            Console::WriteLine( "There is no configured JScript language provider." );
         }

      }

      static void DisplayCompilerInfoUsingExtension( String^ fileExtension )
      {
         if (  !fileExtension->StartsWith(  "." ) )
            fileExtension = String::Concat( ".", fileExtension );

         // Get the language associated with the file extension.
         CodeDomProvider^ provider = nullptr;
         if ( CodeDomProvider::IsDefinedExtension( fileExtension ) )
         {
            String^ language = CodeDomProvider::GetLanguageFromExtension( fileExtension );
            if ( language )
               Console::WriteLine( "The language \"{0}\" is associated with file extension \"{1}\"\n",
                                    language, fileExtension );

            // Check for a corresponding language provider.
            if ( language && CodeDomProvider::IsDefinedLanguage( language ) )
            {
               provider = CodeDomProvider::CreateProvider( language );
               if ( provider )
               {
                  // Display information about this language provider.
                  Console::WriteLine( "Language provider:  {0}\n", provider->ToString() );
                  
                  // Get the compiler settings for this language.
                  CompilerInfo^ langCompilerInfo = CodeDomProvider::GetCompilerInfo( language );
                  if ( langCompilerInfo )
                  {
                     CompilerParameters^ langCompilerConfig = langCompilerInfo->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 language provider associated with input file extension \"{0}\".", fileExtension );

      }

      static void DisplayCompilerInfoForLanguage( String^ language )
      {
         CodeDomProvider^ provider = nullptr;
         
         // Check for a provider corresponding to the input language.  
         if ( CodeDomProvider::IsDefinedLanguage( language ) )
         {
            provider = CodeDomProvider::CreateProvider( language );
            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.
               CompilerInfo^ langCompilerInfo = CodeDomProvider::GetCompilerInfo( language );
               if ( langCompilerInfo )
               {
                  CompilerParameters^ langCompilerConfig = langCompilerInfo->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}\".", language );

      }

      static void DisplayCompilerInfoForConfigLanguage( String^ configLanguage )
      {
         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 );

      }

      static void DisplayAllCompilerInfo()
      {
         array<CompilerInfo^>^allCompilerInfo = CodeDomProvider::GetAllCompilerInfo();
         for ( int i = 0; i < allCompilerInfo->Length; i++ )
         {
            String^ defaultLanguage;
            String^ defaultExtension;
            CompilerInfo^ info = allCompilerInfo[ i ];
            CodeDomProvider^ provider = nullptr;
            if ( info )
               provider = info->CreateProvider();

            if ( provider )
            {
               // Display information about this configured provider.
               Console::WriteLine( "Language provider:  {0}", provider->ToString() );
               Console::WriteLine();
               Console::WriteLine( "  Supported file extension(s):" );
               array<String^>^extensions = info->GetExtensions();
               for ( int i = 0; i < extensions->Length; i++ )
                   Console::WriteLine( "    {0}", extensions[ i ] );

               defaultExtension = provider->FileExtension;
               if (  !defaultExtension->StartsWith( "." ) )
                   defaultExtension = String::Concat( ".", defaultExtension );

               Console::WriteLine( "  Default file extension:  {0}\n", defaultExtension );
               Console::WriteLine( "  Supported language(s):" );
               array<String^>^languages = info->GetLanguages();
               for ( int i = 0; i < languages->Length; i++ )
                   Console::WriteLine( "    {0}", languages[ i ] );

               defaultLanguage = CodeDomProvider::GetLanguageFromExtension( defaultExtension );
               Console::WriteLine(  "  Default language:        {0}", defaultLanguage );
               Console::WriteLine();
               
               // Get the compiler settings for this provider.
               CompilerParameters^ langCompilerConfig = info->CreateDefaultCompilerParameters();
               if ( langCompilerConfig )
               {
                  Console::WriteLine( "  Compiler options:        {0}", langCompilerConfig->CompilerOptions );
                  Console::WriteLine( "  Compiler warning level:  {0}", langCompilerConfig->WarningLevel.ToString() );
               }
            }

         }
      }

   };

}


// The main entry point for the application.

[STAThread]
int main( int argc, char *argv[] )
{
    CodeDomCompilerInfoSample::CompilerInfoSample::Main( Environment::GetCommandLineArgs() );
    Console::WriteLine("\n\nPress ENTER to return");
    Console::ReadLine();
}
// Command-line argument examples:
//      - Displays Visual Basic, C#, and JScript compiler settings.
//   <exe_name> Language CSharp
//      - Displays the compiler settings for C#.
//   <exe_name> All
//      - Displays settings for all configured compilers.
//   <exe_name> Config Pascal
//      - Displays settings for configured Pascal language provider,
//        if one exists.
//   <exe_name> Extension .vb
//      - Displays settings for the compiler associated with the .vb
//        file extension.

using System;
using System.Globalization;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using Microsoft.VisualBasic;

namespace CodeDomCompilerInfoSample
{
    class CompilerInfoSample
    {
        [STAThread]
        static void Main(string[] args)
        {
            String queryCommand = "";
            String queryArg = "";
            int iNumArguments = args.Length;

            // Get input command-line arguments.
            if (iNumArguments > 0)
            {
                queryCommand = args[0].ToUpper(CultureInfo.InvariantCulture);

                if (iNumArguments > 1)
                {
                    queryArg = args[1];
                }
            }

            // Determine which method to call.

            Console.WriteLine();
            switch(queryCommand)
            {
                case ("LANGUAGE"):
                    // Display compiler information for input language.
                    DisplayCompilerInfoForLanguage(queryArg);
                    break;

                case ("EXTENSION"):
                    // Display compiler information for input file extension.
                    DisplayCompilerInfoUsingExtension(queryArg);
                    break;

                case ("CONFIG"):
                    // Display settings for the configured language provider.
                    DisplayCompilerInfoForConfigLanguage(queryArg);
                    break;

                case ("ALL"):
                    // Display compiler information for all configured
                    // language providers.
                    DisplayAllCompilerInfo();
                    break;

                default:
                    // There was no command-line argument, or the
                    // command-line argument was not recognized.
                    // Display the C#, Visual Basic and JScript
                    // compiler information.

                    DisplayCSharpCompilerInfo();
                    DisplayVBCompilerInfo();
                    DisplayJScriptCompilerInfo();
                    break;
            }
        }

        static void DisplayCSharpCompilerInfo()
        {
            // Get the provider for Microsoft.CSharp
            CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

            // Display the C# language provider information.
            Console.WriteLine("CSharp provider is {0}",
                provider.ToString());
            Console.WriteLine("  Provider hash code:     {0}",
                provider.GetHashCode().ToString());
            Console.WriteLine("  Default file extension: {0}",
                provider.FileExtension);

            Console.WriteLine();
        }

        static void DisplayVBCompilerInfo()
        {
            // Get the provider for Microsoft.VisualBasic
            CodeDomProvider provider = CodeDomProvider.CreateProvider("VisualBasic");

            // Display the Visual Basic language provider information.
            Console.WriteLine("Visual Basic provider is {0}",
                provider.ToString());
            Console.WriteLine("  Provider hash code:     {0}",
                provider.GetHashCode().ToString());
            Console.WriteLine("  Default file extension: {0}",
                provider.FileExtension);

            Console.WriteLine();
        }

        static void DisplayJScriptCompilerInfo()
        {
            // Get the provider for JScript.
            CodeDomProvider provider;

            try
            {
                provider = CodeDomProvider.CreateProvider("js");

                // Display the JScript language provider information.
                Console.WriteLine("JScript language provider is {0}",
                    provider.ToString());
                Console.WriteLine("  Provider hash code:     {0}",
                    provider.GetHashCode().ToString());
                Console.WriteLine("  Default file extension: {0}",
                    provider.FileExtension);
                Console.WriteLine();
            }
            catch (System.Configuration.ConfigurationException)
            {
                // The JScript language provider was not found.
                Console.WriteLine("There is no configured JScript language provider.");
            }
        }

        static void DisplayCompilerInfoUsingExtension(string fileExtension)
        {
            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);
                Console.WriteLine();

                // 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}",
                        provider.ToString());
                    Console.WriteLine();

                    // Get the compiler settings for this language.

                    CompilerInfo langCompilerInfo = CodeDomProvider.GetCompilerInfo(language);
                    CompilerParameters langCompilerConfig = langCompilerInfo.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 language provider associated with input file extension \"{0}\".",
                    fileExtension);
            }
        }

        static void DisplayCompilerInfoForLanguage(string language)
        {
            CodeDomProvider provider;

            // Check for a provider corresponding to the input language.
            if (CodeDomProvider.IsDefinedLanguage(language))
            {
                provider = CodeDomProvider.CreateProvider(language);

                // 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.

                CompilerInfo langCompilerInfo = CodeDomProvider.GetCompilerInfo(language);
                CompilerParameters langCompilerConfig = langCompilerInfo.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}\".",
                    language);
            }
        }

        static void DisplayCompilerInfoForConfigLanguage(string 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);
            }
        }

        static void DisplayAllCompilerInfo()
        {
            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();
            }
        }
    }
}
' Command-line argument examples:
'      - Displays Visual Basic, C#, and JScript compiler settings.
'   <exe_name> Language CSharp
'      - Displays the compiler settings for C#.
'   <exe_name> All
'      - Displays settings for all configured compilers.
'   <exe_name> Config Pascal
'      - Displays settings for configured Pascal language provider,
'        if one exists.
'   <exe_name> Extension .vb
'      - Displays settings for the compiler associated with the .vb
'        file extension.

Imports System.IO
Imports System.Globalization
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports Microsoft.CSharp
Imports System.ComponentModel

Namespace CodeDomCompilerInfoSample

   Class CompilerInfoSample

      <STAThread()>  _
      Public Shared Sub Main(ByVal args() As String)

        Dim queryCommand As String = ""
        Dim queryArg As String = ""
        Dim iNumArguments As Integer = args.Length
        
        ' Get input command-line arguments.
        If iNumArguments > 0 Then
            queryCommand = args(0).ToUpper(CultureInfo.InvariantCulture)
            
            If iNumArguments > 1 Then
                queryArg = args(1)
            End If
        End If
        
        ' Determine which method to call.
        Console.WriteLine()
        Select Case queryCommand
            Case "LANGUAGE"
                ' Display compiler information for input language.
                DisplayCompilerInfoForLanguage(queryArg)
            Case "EXTENSION"
                ' Display compiler information for input file extension.
                DisplayCompilerInfoUsingExtension(queryArg)
            Case "CONFIG"
                ' Display settings for the configured language provider.
                DisplayCompilerInfoForConfigLanguage(queryArg)
            Case "ALL"
                ' Display compiler information for all configured 
                ' language providers.
                DisplayAllCompilerInfo()
            Case Else
                ' There was no command-line argument, or the 
                ' command-line argument was not recognized.
                ' Display the C#, Visual Basic and JScript 
                ' compiler information.
                DisplayCSharpCompilerInfo()
                DisplayVBCompilerInfo()
                DisplayJScriptCompilerInfo()
        End Select

      End Sub
      
      
      Shared Sub DisplayCSharpCompilerInfo()
         
         ' Get the provider for Microsoft.CSharp
            Dim provider = CodeDomProvider.CreateProvider("CSharp")
         
         ' Display the C# language provider information.
         Console.WriteLine("CSharp provider is {0}", _
            provider.ToString())
         Console.WriteLine("  Provider hash code:     {0}", _
            provider.GetHashCode().ToString())
         Console.WriteLine("  Default file extension: {0}", _
            provider.FileExtension)
         
         Console.WriteLine()
      End Sub
      
      
      Shared Sub DisplayVBCompilerInfo()
         ' Get the provider for Microsoft.VisualBasic
            Dim provider = CodeDomProvider.CreateProvider("VisualBasic")
         
         ' Display the Visual Basic language provider information.
         Console.WriteLine("Visual Basic provider is {0}", _
            provider.ToString())
         Console.WriteLine("  Provider hash code:     {0}", _
            provider.GetHashCode().ToString())
         Console.WriteLine("  Default file extension: {0}", _
            provider.FileExtension)
         
         Console.WriteLine()
      End Sub
      
      
      Shared Sub DisplayJScriptCompilerInfo()
         ' Get the provider for JScript.
         Dim provider As CodeDomProvider
         
         Try
            provider = CodeDomProvider.CreateProvider("js")
            
            ' Display the JScript language provider information.
            Console.WriteLine("JScript language provider is {0}", _
                provider.ToString())
            Console.WriteLine("  Provider hash code:     {0}", _
                provider.GetHashCode().ToString())
            Console.WriteLine("  Default file extension: {0}", _
                provider.FileExtension)
            Console.WriteLine()
         Catch e As System.Configuration.ConfigurationException
            ' The JScript language provider was not found.
            Console.WriteLine("There is no configured JScript language provider.")
         End Try

      End Sub
      
      Shared Sub DisplayCompilerInfoUsingExtension(fileExtension As String)
         If Not fileExtension.StartsWith(".") Then
            fileExtension = "." + fileExtension
         End If

         ' Get the language associated with the file extension.
         If CodeDomProvider.IsDefinedExtension(fileExtension) Then
            Dim provider As CodeDomProvider
            Dim language As String = CodeDomProvider.GetLanguageFromExtension(fileExtension)
            
            Console.WriteLine("The language ""{0}"" is associated with file extension ""{1}""", _
                language, fileExtension)
            Console.WriteLine()
            
            ' Check for a corresponding language provider.
            If CodeDomProvider.IsDefinedLanguage(language) Then
               provider = CodeDomProvider.CreateProvider(language)
               
               ' Display information about this language provider.
               Console.WriteLine("Language provider:  {0}", _
                  provider.ToString())
               Console.WriteLine()
               
               ' Get the compiler settings for this language.
               Dim langCompilerInfo As CompilerInfo = CodeDomProvider.GetCompilerInfo(language)
               Dim langCompilerConfig As CompilerParameters = langCompilerInfo.CreateDefaultCompilerParameters()
               
               Console.WriteLine("  Compiler options:        {0}", _
                   langCompilerConfig.CompilerOptions)
               Console.WriteLine("  Compiler warning level:  {0}", _
                   langCompilerConfig.WarningLevel)
            End If
         Else
            ' Tell the user that the language provider was not found.
            Console.WriteLine("There is no language provider associated with input file extension ""{0}"".", fileExtension)
         End If
      End Sub
     
      
      Shared Sub DisplayCompilerInfoForLanguage(language As String)
         Dim provider As CodeDomProvider
         
         ' Check for a provider corresponding to the input language.  
         If CodeDomProvider.IsDefinedLanguage(language) Then
            provider = CodeDomProvider.CreateProvider(language)
            
            ' 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 langCompilerInfo As CompilerInfo = CodeDomProvider.GetCompilerInfo(language)
            Dim langCompilerConfig As CompilerParameters = langCompilerInfo.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}"".", _
                language)
         End If

      End Sub
      
      Shared Sub DisplayCompilerInfoForConfigLanguage(configLanguage As String)
         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
      End Sub
      
      
      Shared Sub DisplayAllCompilerInfo()
         Dim allCompilerInfo As CompilerInfo() = CodeDomProvider.GetAllCompilerInfo()
         Dim info As CompilerInfo
         For Each info In  allCompilerInfo

            Dim defaultLanguage As String
            Dim defaultExtension As String

            Dim provider As CodeDomProvider = info.CreateProvider()
            
            ' Display information about this configured provider.
            Console.WriteLine("Language provider:  {0}", _
                provider.ToString())
            Console.WriteLine()
            
            Console.WriteLine("  Supported file extension(s):")
            Dim extension As String
            For Each extension In info.GetExtensions()
               Console.WriteLine("    {0}", extension)
            Next extension
            
            defaultExtension = provider.FileExtension
            If Not defaultExtension.StartsWith(".") Then
               defaultExtension = "." + defaultExtension
            End If
 
            Console.WriteLine("  Default file extension:  {0}", _
              defaultExtension)
            Console.WriteLine()
            
            Console.WriteLine("  Supported language(s):")
            Dim language As String
            For Each language In  info.GetLanguages()
               Console.WriteLine("    {0}", language)
            Next language
            defaultLanguage = CodeDomProvider.GetLanguageFromExtension(defaultExtension)
            Console.WriteLine("  Default language:        {0}", _
               defaultLanguage)
            Console.WriteLine()
            
            ' Get the compiler settings for this provider.
            Dim langCompilerConfig As CompilerParameters = info.CreateDefaultCompilerParameters()
            
            Console.WriteLine("  Compiler options:        {0}", _
                langCompilerConfig.CompilerOptions)
            Console.WriteLine("  Compiler warning level:  {0}", _
                langCompilerConfig.WarningLevel)
            Console.WriteLine()
         Next info
      End Sub

   End Class
End Namespace 'CodeDomCompilerInfoSample

설명

사용 된 CompilerInfo 구현이 컴퓨터에 구성 되어 있는지 여부를 확인 하거나 특정 언어 공급자에 대 한 CodeDomProvider 구성 및 컴파일러 설정을 검사 하는 클래스입니다.

컴퓨터 구성 파일의 system.codedom> 요소에는 언어 공급자 및 컴파일러 구성 설정이 포함됩니다.< 구성된 각 언어 공급자에는 해당 컴파일러 구성 요소가 있습니다. 각 요소는 구현 형식, 지원되는 언어 이름, 지원되는 파일 이름 확장명 및 컴파일러 매개 변수를 정의 CodeDomProvider 합니다.

.NET Framework 컴퓨터 구성 파일에서 초기 컴파일러 설정을 정의합니다. 개발자 및 컴파일러 공급업체는 새로운 CodeDomProvider 구현에 대한 구성 설정을 추가할 수 있습니다.

클래스는 CompilerInfo 컴퓨터 구성 파일에서 이러한 설정에 대한 읽기 전용 액세스를 제공합니다. , GetExtensionsCodeDomProviderType 멤버를 GetLanguages사용하여 언어 공급자에 대한 해당 구성 특성을 검사합니다. 메서드를 CreateDefaultCompilerParameters 사용하여 언어 공급자에 대한 컴파일러 옵션 및 경고 수준 특성 값을 가져옵니다.

구성 파일의 언어 공급자 설정에 대한 자세한 내용은 컴파일러 및 언어 공급자 설정 스키마를 참조하세요.

참고

이 클래스는 모든 멤버에 적용 되는 클래스 수준에서 링크 요청을 포함 합니다. SecurityException 직접 실행 호출자에 full trust 권한이 없는 경우 throw 됩니다. 링크 요구 사항에 대한 자세한 내용은 링크 요구를 참조하세요.

속성

CodeDomProviderType

구성된 CodeDomProvider 구현의 형식을 가져옵니다.

IsCodeDomProviderTypeValid

언어 공급자 구현이 컴퓨터에 구성되어 있는지 여부를 나타내는 값을 반환합니다.

메서드

CreateDefaultCompilerParameters()

언어 공급자 구현에 대해 구성된 컴파일러 설정을 가져옵니다.

CreateProvider()

현재 언어 공급자 설정에 대한 CodeDomProvider 인스턴스를 반환합니다.

CreateProvider(IDictionary<String,String>)

현재 언어 공급자 설정과 지정된 옵션에 대한 CodeDomProvider 인스턴스를 반환합니다.

Equals(Object)

지정된 개체가 현재 CompilerInfo와 같은 언어 공급자 및 컴파일러 설정을 나타내는지 여부를 확인합니다.

GetExtensions()

언어 공급자에서 지원하는 파일 이름 확장명을 반환합니다.

GetHashCode()

현재 인스턴스의 해시 코드를 반환합니다.

GetLanguages()

언어 공급자에서 지원하는 언어 이름을 가져옵니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보