Load All Dependencies - CSharp System.Reflection

CSharp examples for System.Reflection:Assembly

Description

Load All Dependencies

Demo Code


using System.Reflection;
using System;//from   w  ww .  j av  a  2 s .com

public class Main{
        public static void LoadAllDependencies(this Assembly assembly)
        {
            assembly.LoadAllDependencies(x => true);
        }
        public static void LoadAllDependencies(this Assembly assembly, Func<AssemblyName, bool> dependentAssemblyMatcher)
        {
            foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies())
            {
                if (dependentAssemblyMatcher(assemblyName))
                {
                    Assembly referencedAssembly = Assembly.Load(assemblyName);
                    referencedAssembly.LoadAllDependencies(dependentAssemblyMatcher);
                }
            }
        }
}

Related Tutorials