internal static ReferenceAssemblyType GetPathToReferenceAssembly(Assembly a, out string path, ICollection <BuildErrorEventArgs> errors, ICollection <BuildWarningEventArgs> warnings, bool checkDependencies)
        {
            lock (s_lock)
            {
                if (AssemblyLocations.TryGetValue(a, out path))
                {
                    return(ReferenceAssemblyTypes[a]);
                }
            }
            if ((TargetFrameworkReferenceAssemblyPaths == null) || (TargetFrameworkReferenceAssemblyPaths.Count == 0))
            {
                path = Util.GetAssemblyCodeBase(a);
                return(ReferenceAssemblyType.FrameworkAssembly);
            }
            AssemblyResolutionResult result = null;
            ReferenceAssemblyType    nonFrameworkAssembly = ReferenceAssemblyType.NonFrameworkAssembly;

            if (BuildResultCompiledAssemblyBase.AssemblyIsInCodegenDir(a))
            {
                path = Util.GetAssemblyCodeBase(a);
            }
            else
            {
                nonFrameworkAssembly = GetPathToReferenceAssembly(a, out path, errors, warnings, checkDependencies, true, out result);
            }
            StoreResults(a, path, result, nonFrameworkAssembly);
            return(nonFrameworkAssembly);
        }
 private static void StoreResults(Assembly a, string path, AssemblyResolutionResult result, ReferenceAssemblyType assemblyType)
 {
     lock (s_lock) {
         if (!AssemblyLocations.ContainsKey(a))
         {
             AssemblyLocations.Add(a, path);
             AssemblyResolutionResults.Add(a, result);
             ReferenceAssemblyTypes.Add(a, assemblyType);
         }
     }
 }
        internal static ReferenceAssemblyType GetPathToReferenceAssembly(Assembly a, out string path,
                                                                         ICollection <BuildErrorEventArgs> errors, ICollection <BuildWarningEventArgs> warnings,
                                                                         bool checkDependencies)
        {
            lock (s_lock) {
                if (AssemblyLocations.TryGetValue(a, out path))
                {
                    return(ReferenceAssemblyTypes[a]);
                }
            }

            // If there are no reference assemblies available, just use the path to the loaded assembly.
            if (TargetFrameworkReferenceAssemblyPaths == null || TargetFrameworkReferenceAssemblyPaths.Count == 0)
            {
                path = System.Web.UI.Util.GetAssemblyCodeBase(a);
                return(ReferenceAssemblyType.FrameworkAssembly);
            }

            AssemblyResolutionResult result = null;
            ReferenceAssemblyType    referenceAssemblyType = ReferenceAssemblyType.NonFrameworkAssembly;

            // If the assembly is generated by us, it is a non framework assembly and does not need to be resolved.
            if (BuildResultCompiledAssemblyBase.AssemblyIsInCodegenDir(a))
            {
                path = System.Web.UI.Util.GetAssemblyCodeBase(a);
            }
            else
            {
                // Try using the assembly full name.
                referenceAssemblyType = GetPathToReferenceAssembly(a, out path, errors, warnings,
                                                                   checkDependencies, true /*useFullName*/, out result);
            }

            StoreResults(a, path, result, referenceAssemblyType);
            return(referenceAssemblyType);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Evaluator"/> class. This constructor can be
        /// used by classes that inherit the compiler to change the base type of the compiled
        /// producer class.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        /// <param name="producerType">Type of the producer.</param>
        protected Evaluator(ICompiler compiler, Type producerType = null)
        {
            if (compiler == null)
            {
                throw new ArgumentNullException(nameof(compiler));
            }

            _compiler = compiler;

            if (producerType != null && this._producerType != producerType)
            {
                if (!typeof(IProducer).IsAssignableFrom(producerType))
                {
                    throw new NotSupportedException("The baseType parameter needs to be an implementation of IProducer.");
                }

                this._producerType = producerType;
                AssemblyLocations.Add(producerType.Assembly.Location);
            }

            Usings.Add("System");
            AssemblyLocations.Add(typeof(object).Assembly.Location);
            AssemblyLocations.Add(typeof(IProducer).Assembly.Location);
        }