संपादित करें

इसके माध्यम से साझा किया गया


CompilerResults Class

Definition

Represents the results of compilation that are returned from a compiler.

public ref class CompilerResults
public class CompilerResults
[System.Serializable]
public class CompilerResults
type CompilerResults = class
[<System.Serializable>]
type CompilerResults = class
Public Class CompilerResults
Inheritance
CompilerResults
Derived
Attributes

Examples

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

Remarks

This class contains the following information about the results of a compilation by an ICodeCompiler interface implementation:

  • The CompiledAssembly property indicates the compiled assembly.

  • The Evidence property indicates the security evidence for the assembly.

  • The PathToAssembly property indicates the path to the compiled assembly, if it was not generated only in memory.

  • The Errors property indicates any compiler errors and warnings.

  • The Output property contains the compiler output messages.

  • The NativeCompilerReturnValue property indicates result code value returned by the compiler.

  • The TempFiles property indicates the temporary files generated during compilation and linking.

Note

This class contains an inheritance demand at the class level that applies to all members. A SecurityException is thrown when the derived class does not have full-trust permission. For details about inheritance demands, see Inheritance Demands.

Constructors

CompilerResults(TempFileCollection)

Initializes a new instance of the CompilerResults class that uses the specified temporary files.

Properties

CompiledAssembly

Gets or sets the compiled assembly.

Errors

Gets the collection of compiler errors and warnings.

Evidence
Obsolete.

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.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also