CompilerInfoとは? わかりやすく解説

CompilerInfo クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

言語プロバイダ構成設定表します。このクラス継承できません。

名前空間: System.CodeDom.Compiler
アセンブリ: System (system.dll 内)
構文構文

Public NotInheritable Class
 CompilerInfo
public sealed class CompilerInfo
public ref class CompilerInfo sealed
public final class CompilerInfo
public final class CompilerInfo
解説解説

CompilerInfo クラス使用してコンピュータに CodeDomProvider 実装構成されているかどうか判断したり、特定の言語プロバイダ構成設定コンパイラ設定チェックしたりします

マシン構成ファイルの <system.codedom> 要素 には、言語プロバイダおよびコンパイラ構成設定格納されます。構成済み各言語プロバイダは、対応するコンパイラ構成要素持ちます各要素は、CodeDomProvider 実装種類サポートする言語名、サポートするファイル名拡張子、およびコンパイラ パラメータ定義します

.NET Framework では、マシン構成ファイル初期コンパイラ設定定義します開発者およびコンパイラ販売元は、新しCodeDomProvider 実装構成設定追加できます

CompilerInfo クラスは、マシン構成ファイルのこれらの設定への読み取り専用アクセス提供します言語プロバイダ対応する構成属性チェックするには、GetLanguages、GetExtensions、および CodeDomProviderType の各メンバ使用します言語プロバイダコンパイラ オプションおよび警告レベル属性値取得するには、CreateDefaultCompilerParameters メソッド使用します

構成ファイル言語プロバイダ設定詳細については、「コンパイラおよび言語プロバイダ設定スキーマ」を参照してください

メモメモ

このクラスには、すべてのメンバ適用されるクラス レベルのリンク確認要求格納されます。直前呼び出し元に完全信頼アクセス許可ない場合、SecurityException がスローさます。リンク確認要求詳細については、「リンク確認要求」を参照してください

使用例使用例

言語プロバイダ構成設定表示するコード例次に示しますコマンド ライン引数使用して言語ファイル名拡張子、またはプロバイダ種類指定します。この例では、指定され入力について、対応する言語プロバイダ確認し構成済み言語コンパイラ設定表示します

' Command-line argument examples:
'   <exe_name>
'      - 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
Imports System.IO
Imports System.Globalization
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports Microsoft.CSharp
Imports Microsoft.VisualBasic
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 'Main
      
      
      Shared Sub DisplayCSharpCompilerInfo()
         
         ' Get the provider for Microsoft.CSharp
         Dim provider = New CSharpCodeProvider()
         
         ' 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 'DisplayCSharpCompilerInfo
      
      
      Shared Sub DisplayVBCompilerInfo()
         ' Get the provider for Microsoft.VisualBasic
         Dim provider = New VBCodeProvider()
         
         ' 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 'DisplayVBCompilerInfo
      
      
      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 'DisplayJScriptCompilerInfo
      
      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 'DisplayCompilerInfoUsingExtension
     
      
      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 'DisplayCompilerInfoForLanguage
      
      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 'DisplayCompilerInfoForConfigLanguage
      
      
      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 'DisplayAllCompilerInfo
 

   End Class 'CompilerInfoSample
End Namespace 'CodeDomCompilerInfoSample
// Command-line argument examples:
//   <exe_name>
//      - 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 = new CSharpCodeProvider();

            // 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 = new VBCodeProvider();

            // 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:
//   <exe_name>
//      - 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" )
 )
         {
            
            // Display compiler information for input language.
            DisplayCompilerInfoForLanguage( queryArg );
         }
         else
         if ( queryCommand->Equals( "EXTENSION" )
 )
         {
            
            // Display compiler information for input file extension.
            DisplayCompilerInfoUsingExtension( queryArg );
         }
         else
         if ( queryCommand->Equals( "CONFIG" ) )
         {
            
            // Display settings for the configured language provider.
            DisplayCompilerInfoForConfigLanguage( queryArg );
         }
         else
         if ( queryCommand->Equals( "ALL" ) )
         {
            
            // Display compiler information for all configured 
            // language providers.
            DisplayAllCompilerInfo();
         }
         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 = gcnew CSharpCodeProvider;
         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 = gcnew VBCodeProvider;
         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( "js" );
            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}\"", language, fileExtension );
               Console::WriteLine();
            }

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

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
  System.CodeDom.Compiler.CompilerInfo
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
CompilerInfo メンバ
System.CodeDom.Compiler 名前空間
CompilerParameters
CodeDomProvider クラス
その他の技術情報
コンパイラおよび言語プロバイダ設定スキーマ

CompilerInfo プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ CodeDomProviderType 構成済みの CodeDomProvider 実装種類取得します
パブリック プロパティ IsCodeDomProviderTypeValid コンピュータ上に言語プロバイダ実装構成されているかどうかを示す値を返します
参照参照

関連項目

CompilerInfo クラス
System.CodeDom.Compiler 名前空間
CompilerParameters
CodeDomProvider クラス

その他の技術情報

コンパイラおよび言語プロバイダ設定スキーマ

CompilerInfo メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

CompilerInfo クラス
System.CodeDom.Compiler 名前空間
CompilerParameters
CodeDomProvider クラス

その他の技術情報

コンパイラおよび言語プロバイダ設定スキーマ

CompilerInfo メンバ

言語プロバイダ構成設定表します。このクラス継承できません。

CompilerInfo データ型公開されるメンバを以下の表に示します


パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ CodeDomProviderType 構成済みCodeDomProvider 実装種類取得します
パブリック プロパティ IsCodeDomProviderTypeValid コンピュータ上に言語プロバイダ実装構成されているかどうかを示す値を返します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

CompilerInfo クラス
System.CodeDom.Compiler 名前空間
CompilerParameters
CodeDomProvider クラス

その他の技術情報

コンパイラおよび言語プロバイダ設定スキーマ



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「CompilerInfo」の関連用語

CompilerInfoのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



CompilerInfoのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS