예제 #1
0
        /// <summary>
        /// Finds an assembly that exactly matches the requested assembly
        /// </summary>
        /// <param name="assembly">Assembly name to find</param>
        /// <param name="paths">Search paths or <c>null</c> if none</param>
        /// <param name="moduleContext">Module context</param>
        /// <returns>An <see cref="AssemblyDef"/> instance or <c>null</c> if an exact match
        /// couldn't be found.</returns>
        AssemblyDef FindExactAssembly(IAssembly assembly, IEnumerable <string> paths, ModuleContext moduleContext)
        {
            if (paths == null)
            {
                return(null);
            }
            var asmComparer = new AssemblyNameComparer(AssemblyNameComparerFlags.All);

            foreach (var path in paths.GetSafeEnumerable())
            {
                ModuleDefMD mod = null;
                try {
                    mod = ModuleDefMD.Load(path, moduleContext);
                    var asm = mod.Assembly;
                    if (asm != null && asmComparer.Equals(assembly, asm))
                    {
                        mod = null;
                        return(asm);
                    }
                }
                catch {
                }
                finally {
                    if (mod != null)
                    {
                        mod.Dispose();
                    }
                }
            }
            return(null);
        }
예제 #2
0
        /// <summary>
        /// Finds the closest assembly from the already cached assemblies
        /// </summary>
        /// <param name="assembly">Assembly name to find</param>
        /// <returns>The closest <see cref="AssemblyDef"/> or <c>null</c> if none found</returns>
        AssemblyDef FindClosestAssembly(IAssembly assembly)
        {
            AssemblyDef closest = null;
            var asmComparer     = new AssemblyNameComparer(AssemblyNameComparerFlags.All);

            foreach (var asm in cachedAssemblies.Values)
            {
                if (asm == null)
                {
                    continue;
                }
                if (asmComparer.CompareClosest(assembly, closest, asm) == 1)
                {
                    closest = asm;
                }
            }
            return(closest);
        }
예제 #3
0
        AssemblyDef FindClosestAssembly(IAssembly assembly, AssemblyDef closest, IEnumerable <string> paths, ModuleContext moduleContext)
        {
            if (paths == null)
            {
                return(closest);
            }
            var asmComparer = new AssemblyNameComparer(AssemblyNameComparerFlags.All);

            foreach (var path in paths.GetSafeEnumerable())
            {
                ModuleDefMD mod = null;
                try {
                    mod = ModuleDefMD.Load(path, moduleContext);
                    var asm = mod.Assembly;
                    if (asm != null && asmComparer.CompareClosest(assembly, closest, asm) == 1)
                    {
                        if (!IsCached(closest) && closest != null)
                        {
                            var closeMod = closest.ManifestModule;
                            if (closeMod != null)
                            {
                                closeMod.Dispose();
                            }
                        }
                        closest = asm;
                        mod     = null;
                    }
                }
                catch {
                }
                finally {
                    if (mod != null)
                    {
                        mod.Dispose();
                    }
                }
            }

            return(closest);
        }