次の方法で共有


CompilerResults クラス

コンパイラから返されるコンパイル結果を表します。

この型のすべてのメンバの一覧については、CompilerResults メンバ を参照してください。

System.Object
   System.CodeDom.Compiler.CompilerResults

Public Class CompilerResults
[C#]
public class CompilerResults
[C++]
public __gc class CompilerResults
[JScript]
public class CompilerResults

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

このクラスには、 ICodeCompiler インターフェイスの実装による、コンパイルの結果に関する以下の情報が含まれています。

  • CompiledAssembly プロパティは、コンパイル済みのアセンブリを示します。
  • Evidence プロパティは、アセンブリのセキュリティ証拠を示します。
  • PathToAssembly プロパティは、生成先がメモリだけではない場合に、コンパイルされたアセンブリへのパスを示します。
  • Errors プロパティは、コンパイラのエラーや警告を示します。
  • Output プロパティは、コンパイラの出力メッセージを格納します。
  • NativeCompilerReturnValue プロパティは、コンパイラによって返される結果コードの値を示します。
  • TempFiles プロパティは、コンパイルやリンクの間に生成される一時ファイルを示します。

使用例

 
' Displays information from a CompilerResults.
Public Shared Sub DisplayCompilerResults(ByVal cr As System.CodeDom.Compiler.CompilerResults)
    ' If errors occurred during compilation, output the compiler output and errors.
    If cr.Errors.Count > 0 Then
        Dim i As Integer
        For i = 0 To cr.Output.Count - 1
            Console.WriteLine(cr.Output(i))
        Next i        
        For i = 0 To cr.Errors.Count - 1
            Console.WriteLine((i.ToString() + ": " + cr.Errors(i).ToString()))
        Next i
    Else
        ' Display information about the compiler's exit code and the generated assembly.
        Console.WriteLine(("Compiler returned with result code: " + cr.NativeCompilerReturnValue.ToString()))
        Console.WriteLine(("Generated assembly name: " + cr.CompiledAssembly.FullName))
        If cr.PathToAssembly Is Nothing Then
            Console.WriteLine("The assembly has been generated in memory.")
        Else
            Console.WriteLine(("Path to assembly: " + cr.PathToAssembly))
        End If
        ' Display temporary files information.
        If Not cr.TempFiles.KeepFiles Then
            Console.WriteLine("Temporary build files were deleted.")
        Else
            Console.WriteLine("Temporary build files were not deleted.")
            ' Display a list of the temporary build files
            Dim enu As IEnumerator = cr.TempFiles.GetEnumerator()
            Dim i As Integer
            i = 0
            While enu.MoveNext()
                Console.WriteLine(("TempFile " + i.ToString() + ": " + CStr(enu.Current)))
                i += 1
            End While
        End If
    End If
End Sub

[C#] 
// Displays information from a CompilerResults.
public static void DisplayCompilerResults(System.CodeDom.Compiler.CompilerResults cr)
{
    // If errors occurred during compilation, output the compiler output and errors.
    if( cr.Errors.Count > 0 )
    {
        for( int i=0; i<cr.Output.Count; i++ )                
            Console.WriteLine( cr.Output[i] );
        for( int i=0; i<cr.Errors.Count; i++ )                
            Console.WriteLine( i.ToString() + ": " + cr.Errors[i].ToString() );
        
    }
    else
    {
        // Display information about the compiler's exit code and the generated assembly.
        Console.WriteLine( "Compiler returned with result code: " + cr.NativeCompilerReturnValue.ToString() );
        Console.WriteLine( "Generated assembly name: " + cr.CompiledAssembly.FullName );
        if( cr.PathToAssembly == null )
            Console.WriteLine( "The assembly has been generated in memory." );
        else
            Console.WriteLine( "Path to assembly: " + cr.PathToAssembly );
        
        // Display temporary files information.
        if( !cr.TempFiles.KeepFiles )                
            Console.WriteLine( "Temporary build files were deleted." );
        else
        {
            Console.WriteLine( "Temporary build files were not deleted." );
            // Display a list of the temporary build files
            IEnumerator enu = cr.TempFiles.GetEnumerator();                                        
            for( int i=0; enu.MoveNext(); i++ )                                          
                Console.WriteLine( "TempFile " + i.ToString() + ": " + (string)enu.Current );                  
        }
    }
}

[C++] 
// Displays information from a CompilerResults.
public:
static void DisplayCompilerResults(System::CodeDom::Compiler::CompilerResults* cr) {
   // If errors occurred during compilation, output the compiler output and errors.
   if (cr->Errors->Count > 0) {
      for (int i=0; i<cr->Output->Count; i++)
         Console::WriteLine(cr->Output->Item[i]);
      for (int i=0; i<cr->Errors->Count; i++)
         Console::WriteLine(String::Concat( __box(i), S": ", cr->Errors->Item[i]));

   } else {
      // Display information ab->Item[Out] the* compiler's exit code and the generated assembly.
      Console::WriteLine(S"Compiler returned with result code: {0}", 
         __box(cr->NativeCompilerReturnValue));
      Console::WriteLine(S"Generated assembly name: {0}",
         cr->CompiledAssembly->FullName);
      if (cr->PathToAssembly == 0)
         Console::WriteLine(S"The assembly has been generated in memory.");
      else
         Console::WriteLine(S"Path to assembly: {0}",
         cr->PathToAssembly);

      // Display temporary files information.
      if (!cr->TempFiles->KeepFiles)
         Console::WriteLine(S"Temporary build files were deleted.");
      else {
         Console::WriteLine(S"Temporary build files were not deleted.");
         // Display a list of the temporary build files
         IEnumerator* enu = cr->TempFiles->GetEnumerator();
         for (int i=0; enu->MoveNext(); i++)
            Console::WriteLine(String::Concat(S"TempFile ", __box(i), S": ",
              dynamic_cast<String*>(enu->Current)));
      }
   }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.CodeDom.Compiler

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System (System.dll 内)

参照

CompilerResults メンバ | System.CodeDom.Compiler 名前空間 | ICodeCompiler