コード例 #1
0
 public virtual void SaveOrLoadAssembly(AssemblyNode assem, CompilerParameters options, CompilerResults results, ErrorNodeList errorNodes){
   if (assem == null) return;
   AssemblyReferenceList arefs = assem.AssemblyReferences;
   //TODO: give the error in the context of the member that made the reference
   for (int i = 0, n = arefs == null ? 0 : arefs.Count; i < n; i++){
     AssemblyReference aref = arefs[i];
     if (aref == null || aref.Assembly == null) continue;
     ArrayList metadataErrors = aref.Assembly.MetadataImportErrors;
     if (metadataErrors == null) continue;
     foreach (Exception mdErr in metadataErrors)
       if (mdErr.Message.StartsWith("Assembly reference not resolved"))
         results.Errors.Add(new CompilerError(aref.Assembly.Name+".dll", 0, 0, "0", mdErr.Message));
   }
   if (results.NativeCompilerReturnValue != 0) return; //TODO: allow option to override this
   if (options.GenerateInMemory){
     System.Security.Policy.Evidence evidence = options.Evidence;
     CompilerOptions cOptions = options as CompilerOptions;
     System.AppDomain targetDomain = cOptions == null ? null : cOptions.TargetAppDomain;
     if (targetDomain == null) targetDomain = AppDomain.CurrentDomain;
     for (int i = 0, n = arefs == null ? 0 : arefs.Count; i < n; i++){
       AssemblyReference aref = arefs[i];
       if (aref == null || aref.Assembly == null) continue;
       aref.Assembly.GetRuntimeAssembly(evidence, targetDomain);
     }
     results.CompiledAssembly = assem.GetRuntimeAssembly(evidence, targetDomain);
   }else{
     ErrorNodeList errors = new ErrorNodeList(0);
     string fileName = this.GetTargetFileName(options, errors);
     this.AddResourcesAndIcons(assem, options, errors);
     if (errors.Count == 0){
       try{
         assem.WriteModule(fileName, options);
       }catch(KeyFileNotFoundException){
         ErrorNode keyFileMissing = this.CreateErrorNode(Error.AssemblyKeyFileMissing, ((CompilerOptions)options).AssemblyKeyFile);
         errors.Add(this.CreateErrorNode(Error.AssemblyCouldNotBeSigned, assem.Location, keyFileMissing.GetMessage()));
         errorNodes.Add(errors[0]);
         this.ProcessErrors(options, results, errors);
       }catch(AssemblyCouldNotBeSignedException){
         ErrorNode unknownCryptoFailure = this.CreateErrorNode(Error.UnknownCryptoFailure);
         errors.Add(this.CreateErrorNode(Error.AssemblyCouldNotBeSigned, assem.Location, unknownCryptoFailure.GetMessage()));
         errorNodes.Add(errors[0]);
         this.ProcessErrors(options, results, errors);
       }catch(Exception e){
         errors.Add(this.CreateErrorNode(Error.InternalCompilerError, e.Message));
         errorNodes.Add(errors[0]);
         this.ProcessErrors(options, results, errors);
       }
       CompilerOptions coptions = options as CompilerOptions;
       if (coptions != null && coptions.XMLDocFileName != null && coptions.XMLDocFileName.Length > 0)
         assem.WriteDocumentation(new StreamWriter(coptions.XMLDocFileName));
       results.PathToAssembly = fileName;
     }else{
       this.ProcessErrors(options, results, errors);
       for (int i = 0, n = errors.Count; i < n; i++)
         errorNodes.Add(errors[i]);
     }
   }
 }