static bool IsNestedTypeOfScriptType(Type t) { Type x = t.DeclaringType; while (x != null) { if (ScriptAttribute.Of(x, false) != null) { return(true); } x = x.DeclaringType; } return(false); }
static IEnumerable <Assembly> LoadReferencedAssemblies(Assembly a) { foreach (AssemblyName z in a.GetReferencedAssemblies()) { var x = AppDomain.CurrentDomain.Load(z); if (ScriptAttribute.Of(x) == null) { continue; } yield return(x); foreach (Assembly c in LoadReferencedAssemblies(x)) { yield return(c); } } }
static IEnumerable <LoadDependenciesValue> LoadDependencies( Assembly context, Assembly a, bool includethis, Action <Assembly> h, bool SkipMissingRefences = false ) { //Console.WriteLine("enter LoadDependencies " // + new // { // Environment.CurrentDirectory, // context = context.Location, // a = a.Location // }); var r = new LoadDependenciesValue(); r.Assembly = a; Action <Assembly> Add = n => { r.Dependencies = r.Dependencies.Concat(new[] { n }).ToArray(); if (h != null) { h(n); } }; var ReferencedAssemblies = a.GetReferencedAssemblies() .Where(k => k.Name != a.GetName().Name) .Select( k => { //Console.WriteLine("LoadDependencies " + new { k.Name }); try { //Additional information: Could not load file or assembly 'System.Data.SQLite, Version=1.0.90.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) //var LocalCopyHint = new FileInfo(a.Location).Directory + "/" + k.Name + ".dll"; //if (File.Exists(LocalCopyHint)) //{ // // 20131226 // return Assembly.LoadFrom(LocalCopyHint); //} return(AppDomain.CurrentDomain.Load(k)); } catch { if (SkipMissingRefences) { return(null); } throw; } } ).Where(k => k != null); var _as = ScriptAttribute.OfProvider(a); if (_as != null) { if (_as.ScriptLibraries != null) { ReferencedAssemblies = ReferencedAssemblies.Concat(_as.ScriptLibraries.Select(k => k.Assembly)); } } foreach (var x in ReferencedAssemblies) { if (ScriptAttribute.Of(x) == null) { // either it is not a script library // or it is in regards to context var cs = ScriptAttribute.OfProvider(context); if (cs != null) { if (cs.ScriptLibraries != null) { if (cs.ScriptLibraries.Any(k => k.Assembly == x)) { goto ContinueAdd; } } } continue; } ContinueAdd: Add(x); foreach (var v in LoadDependencies(context, x, true, Add)) { yield return(v); } } if (includethis) { yield return(r); } }