コード例 #1
0
        public static Assembly resolveAssembly(this string nameOrPath, Func <string, string> resolveName)
        {
            System.ResolveEventHandler assemblyResolve =
                (sender, args) => {
                var name = args.prop("Name").str();
                //"[AssemblyResolve] for name: {0}".debug(name);
                var location = resolveName(name);
                if (location.valid())
                {
                    //"[AssemblyResolve] found location: {0}".info(location);
                    var assembly = Assembly.Load(location.fileContents_AsByteArray());
                    if (assembly.notNull())
                    {
                        //"[AssemblyResolve] loaded Assembly: {0}".info(assembly.FullName);
                        return(assembly);
                    }
                    else
                    {
                        "[AssemblyResolve] failed to load Assembly from location: {0}".error(location);
                    }
                }
                else
                {
                    "[AssemblyResolve] could not find a location for assembly with name: {0}".error(name);
                }
                return(null);
            };

            Func <string, Assembly> loadAssembly =
                (assemblyToLoad) => {
                AppDomain.CurrentDomain.AssemblyResolve += assemblyResolve;
                var assembly = assemblyToLoad.assembly();
                AppDomain.CurrentDomain.AssemblyResolve -= assemblyResolve;
                return(assembly);
            };

            return(loadAssembly(nameOrPath));
        }
コード例 #2
0
 protected void RemoveAssemblyResolver(System.ResolveEventHandler handler)
 {
     AppDomain.CurrentDomain.AssemblyResolve -= handler;
 }