Microsoft.JScript.VsaReference.Compile C# (CSharp) Method

Compile() private method

private Compile ( bool throwOnFileNotFound ) : bool
throwOnFileNotFound bool
return bool
      internal bool Compile(bool throwOnFileNotFound){
        try{
          String assemblyFileName = Path.GetFileName(this.assemblyName);
          String alternateName = assemblyFileName + ".dll";
          if (String.Compare(assemblyFileName, "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0 ||
              String.Compare(alternateName, "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0)
            this.assembly = typeof(Object).Assembly;
          if (String.Compare(assemblyFileName, "microsoft.jscript.dll", StringComparison.OrdinalIgnoreCase) == 0 ||
              String.Compare(alternateName, "microsoft.jscript.dll", StringComparison.OrdinalIgnoreCase) == 0) {
            this.assembly = engine.JScriptModule.Assembly;
          } else if (String.Compare(assemblyFileName, "microsoft.vsa.dll", StringComparison.OrdinalIgnoreCase) == 0 ||
                   String.Compare(alternateName, "microsoft.vsa.dll", StringComparison.OrdinalIgnoreCase) == 0) {
            this.assembly = engine.VsaModule.Assembly;
          } else if (this.engine.ReferenceLoaderAPI != LoaderAPI.ReflectionOnlyLoadFrom) {
              if (String.Compare(assemblyFileName, "system.dll", StringComparison.OrdinalIgnoreCase) == 0 ||
                     String.Compare(alternateName, "system.dll", StringComparison.OrdinalIgnoreCase) == 0)
              this.assembly = typeof(System.Text.RegularExpressions.Regex).Module.Assembly;
          }
          
          if (this.assembly == null) {
            String path = this.engine.FindAssembly(this.assemblyName);
            // if not found, look for the file with ".dll" appended to the assembly name
            if (path == null){
              // check for duplicates before we add the ".dll" part
              alternateName = this.assemblyName + ".dll";
              bool fDuplicate = false;
              foreach (Object item in this.engine.Items){
                if (item is VsaReference && String.Compare(((VsaReference)item).AssemblyName, alternateName, StringComparison.OrdinalIgnoreCase) == 0){
                  fDuplicate = true;
                  break;
                }
              }
              if (!fDuplicate){
                path = this.engine.FindAssembly(alternateName);
                if (path != null)
                  this.assemblyName = alternateName;
              }
            }
            if (path == null){
              if (throwOnFileNotFound)
                throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, new System.IO.FileNotFoundException());
              else
                return false;
            }
            switch (this.engine.ReferenceLoaderAPI) {
              case LoaderAPI.LoadFrom:                this.assembly = Assembly.LoadFrom(path); break;
              case LoaderAPI.LoadFile:                this.assembly = Assembly.LoadFile(path); break;
              case LoaderAPI.ReflectionOnlyLoadFrom:  this.assembly = Assembly.ReflectionOnlyLoadFrom(path); break;
            }
            
            // Warn if building a machine specfic assembly and the referenced assembly is machine
            // specific but does not match.
            CheckCompatibility();
          }
        }catch(VsaException){
          throw;
        }catch(System.BadImageFormatException e){
          throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, e);
        }catch(System.IO.FileNotFoundException e){
          if (throwOnFileNotFound)
            throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, e);
          else
            return false;
        }catch(System.IO.FileLoadException e){
          throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, e);
        }catch(System.ArgumentException e){
          throw new VsaException(VsaError.AssemblyExpected, this.assemblyName, e);
        }catch(Exception e){
          throw new VsaException(VsaError.InternalCompilerError, e.ToString(), e);
        }catch{
          throw new VsaException(VsaError.InternalCompilerError);
        }
        if (this.assembly == null){
          if (throwOnFileNotFound)
            throw new VsaException(VsaError.AssemblyExpected, this.assemblyName);
          else
            return false;
        }
        return true;
      }

Same methods

VsaReference::Compile ( ) : void

Usage Example

Example #1
0
 internal void TryToAddImplicitAssemblyReference(String name){
   if (!this.autoRef) return;
   
   String key;
   SimpleHashtable implictAssemblyCache = this.implicitAssemblyCache;
   if (implicitAssemblyCache == null) {
     //Populate cache with things that should not be autoref'd. Canonical form is lower case without extension.
     implicitAssemblyCache = new SimpleHashtable(50);
     
     //PEFileName always includes an extension and is never NULL.
     implicitAssemblyCache[Path.GetFileNameWithoutExtension(this.PEFileName).ToLower(CultureInfo.InvariantCulture)] = true;
     
     foreach (Object item in this.vsaItems){
       VsaReference assemblyReference = item as VsaReference;
       if (assemblyReference == null || assemblyReference.AssemblyName == null) continue;
       key = Path.GetFileName(assemblyReference.AssemblyName).ToLower(CultureInfo.InvariantCulture);
       if (key.EndsWith(".dll"))
         key = key.Substring(0, key.Length-4);
       implicitAssemblyCache[key] = true;
     }          
     this.implicitAssemblyCache = implicitAssemblyCache;          
   }
   
   key = name.ToLower(CultureInfo.InvariantCulture);
   if (implicitAssemblyCache[key] != null) return;
   implicitAssemblyCache[key] = true;
   
   try{
     VsaReference assemblyReference = new VsaReference(this, name + ".dll");
     if (assemblyReference.Compile(false)){
       ArrayList implicitAssemblies = this.implicitAssemblies;
       if (implicitAssemblies == null) {
          implicitAssemblies = new ArrayList();
          this.implicitAssemblies = implicitAssemblies;
       }
       implicitAssemblies.Add(assemblyReference.Assembly);
     }
   }catch(VsaException){
   }
 }
All Usage Examples Of Microsoft.JScript.VsaReference::Compile