CompilerResults 類別

定義

表示從編譯器傳回的編譯結果。Represents the results of compilation that are returned from a compiler.

public ref class CompilerResults
[System.Serializable]
public class CompilerResults
type CompilerResults = class
Public Class CompilerResults
繼承
CompilerResults
衍生
屬性

範例

// Displays information from a CompilerResults.
[PermissionSet(SecurityAction::Demand, Name="FullTrust")]
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( String::Concat( i, ": ", cr->Errors[ i ] ) );
   }
   else
   {
      
      // Display information ab->Item[Out] the* compiler's exit code and the generated assembly.
      Console::WriteLine( "Compiler returned with result code: {0}", cr->NativeCompilerReturnValue );
      Console::WriteLine( "Generated assembly name: {0}", cr->CompiledAssembly->FullName );
      if ( cr->PathToAssembly == nullptr )
               Console::WriteLine( "The assembly has been generated in memory." );
      else
               Console::WriteLine( "Path to assembly: {0}", 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) );
      }
   }
}
// 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 );                  
        }
    }
}
' 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

備註

此類別包含ICodeCompiler介面實作為編譯結果的下列資訊:This class contains the following information about the results of a compilation by an ICodeCompiler interface implementation:

  • CompiledAssembly屬性會指出已編譯的元件。The CompiledAssembly property indicates the compiled assembly.

  • Evidence屬性會指出元件的安全性辨識項。The Evidence property indicates the security evidence for the assembly.

  • PathToAssembly屬性會指出已編譯元件的路徑 (如果未在記憶體中產生)。The PathToAssembly property indicates the path to the compiled assembly, if it was not generated only in memory.

  • Errors屬性會指出任何編譯器錯誤和警告。The Errors property indicates any compiler errors and warnings.

  • Output屬性包含編譯器輸出訊息。The Output property contains the compiler output messages.

  • NativeCompilerReturnValue屬性會指出編譯器傳回的結果碼值。The NativeCompilerReturnValue property indicates result code value returned by the compiler.

  • TempFiles屬性會指出編譯和連結期間所產生的暫存檔案。The TempFiles property indicates the temporary files generated during compilation and linking.

注意

這個類別包含適用于所有成員之類別層級的繼承要求。This class contains an inheritance demand at the class level that applies to all members. 當衍生類別沒有完全信任許可權時,就會擲回。SecurityExceptionA SecurityException is thrown when the derived class does not have full-trust permission. 如需繼承需求的詳細資訊, 請參閱繼承需求For details about inheritance demands, see Inheritance Demands.

建構函式

CompilerResults(TempFileCollection)

初始化 CompilerResults 類別的新執行個體,這個執行個體會使用指定的暫存檔案。Initializes a new instance of the CompilerResults class that uses the specified temporary files.

屬性

CompiledAssembly

取得或設定已編譯的組件。Gets or sets the compiled assembly.

Errors

取得編譯器錯誤和警告的集合。Gets the collection of compiler errors and warnings.

Evidence

表示代表已編譯組件之安全性原則權限的辨識項物件。Indicates the evidence object that represents the security policy permissions of the compiled assembly.

NativeCompilerReturnValue

取得或設定編譯器的傳回值。Gets or sets the compiler's return value.

Output

取得編譯器輸出訊息。Gets the compiler output messages.

PathToAssembly

取得或設定已編譯組件的路徑。Gets or sets the path of the compiled assembly.

TempFiles

取得或設定要使用的暫存檔案集合。Gets or sets the temporary file collection to use.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

安全性

InheritanceDemand
適用於繼承者的完全信任的。for full trust for inheritors. 此類別無法由部分信任程式碼繼承。This class cannot be inherited by partially trusted code.

適用於

另請參閱