public static void Add(string @namespace, Assembly assembly, Func <DbContext> contextAccessor) { if (Assemblies.ContainsKey(@namespace)) { throw new DuplicateKeyException(@namespace, "Already exists an Assembly for specified namespace."); } Assemblies.Add(@namespace, assembly); Contexts.Add(@namespace, contextAccessor); }
protected override Assembly Load(AssemblyName args) { if (Assemblies.ContainsKey(args.Name)) { return(Assemblies[args.Name]); } var separatorIndex = args.Name.IndexOf(",", StringComparison.Ordinal); var assemblyName = separatorIndex > 0 ? args.Name.Substring(0, separatorIndex) : args.Name; var version = args.Version; if (version != null) { var assemblyByVersion = TryLoadByVersion(AllReferencePaths, assemblyName, version.Major + "." + version.Minor + "." + version.Build + "."); if (assemblyByVersion != null) { Assemblies[args.Name] = assemblyByVersion; return(assemblyByVersion); } assemblyByVersion = TryLoadByVersion(AllReferencePaths, assemblyName, version.Major + "." + version.Minor + "."); if (assemblyByVersion != null) { Assemblies[args.Name] = assemblyByVersion; return(assemblyByVersion); } assemblyByVersion = TryLoadByVersion(AllReferencePaths, assemblyName, version.Major + "."); if (assemblyByVersion != null) { Assemblies[args.Name] = assemblyByVersion; return(assemblyByVersion); } } var assembly = TryLoadByAssemblyName(args.FullName); if (assembly != null) { Assemblies[args.Name] = assembly; return(assembly); } assembly = TryLoadByName(AllReferencePaths, assemblyName); if (assembly != null) { Assemblies[args.Name] = assembly; return(assembly); } Assemblies[args.Name] = TryLoadByAssemblyName(assemblyName); return(Assemblies[args.Name]); }
public void FindAssembly(Assembly assembly) { if (Assemblies.ContainsKey(assembly.FullName)) { return; } Assemblies.Add(assembly.FullName, assembly); foreach (var e in assembly.DefinedTypes) { FindAllType(e); } foreach (var e in Types.Select(e => e.Value.Assembly).ToArray()) { FindAssembly(e); } }
public Assembly Load(string assemblyPath) { var key = assemblyPath.ToLower(); if (!Assemblies.ContainsKey(key)) { #region readme //https://www.codeproject.com/Articles/34301/Assembly-LoadFile-versus-Assembly-LoadFrom-NET-obs //“Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths.” #endregion var assembly = Assembly.LoadFile(assemblyPath); Assemblies[key] = assembly; } return(Assemblies[key]); }
protected JForm CreateJDockForm(string typeStr, string dllName, params object[] constructArgs) { Type type; if (!string.IsNullOrEmpty(dllName))//单独dll存放在插件文件夹 { Assembly assembly = Assemblies.ContainsKey(dllName) ? Assemblies[dllName] : null;; type = assembly.GetType(typeStr); } else { type = Assembly.GetEntryAssembly().GetType(typeStr); //dll为Exe所在程序集 if (type == null) { type = Assembly.GetExecutingAssembly().GetType(typeStr); //dll为当前程序集 } } if (type == null) { this.ShowMessage("工具{0}找不到入口函数", typeStr); return(null); } object obj = null; try { if (constructArgs == null || constructArgs.Length == 0) { obj = Activator.CreateInstance(type); } else { obj = Activator.CreateInstance(type, constructArgs); } } catch (Exception ex) { this.ShowMessage(ex); } JForm formToShow = (JForm)obj; formToShow.MdiParent = this; return(formToShow); }
private static bool Contains(string @namespace) { return(Assemblies.ContainsKey(@namespace) && Contexts.ContainsKey(@namespace)); }
/// <summary> /// Process every definition in the module. /// </summary> private void ProcessInternal() { bool cleanUp = ShouldCleanUp; // Process assembly for (int i = 0; i < Module.Assembly.CustomAttributes.Count; i++) { if (ProcessAny <IAssemblyWeaver>(Module.Assembly.CustomAttributes[i], Module.Assembly) && cleanUp) { i--; } } // Process types foreach (TypeDefinition typeDef in Module.Types) { // Process fields foreach (FieldDefinition fieldDef in typeDef.Fields) { for (int i = 0; i < fieldDef.CustomAttributes.Count; i++) { if (ProcessAny <IFieldWeaver>(fieldDef.CustomAttributes[i], fieldDef) && cleanUp) { i--; } } Weave.TriggerScan(fieldDef); } // Process properties foreach (PropertyDefinition propDef in typeDef.Properties) { for (int i = 0; i < propDef.CustomAttributes.Count; i++) { if (ProcessAny <IPropertyWeaver>(propDef.CustomAttributes[i], propDef) && cleanUp) { i--; } } Weave.TriggerScan(propDef); } // Process events foreach (EventDefinition eventDef in typeDef.Events) { for (int i = 0; i < eventDef.CustomAttributes.Count; i++) { if (ProcessAny <IEventWeaver>(eventDef.CustomAttributes[i], eventDef) && cleanUp) { i--; } } Weave.TriggerScan(eventDef); } // Process methods foreach (MethodDefinition methodDef in typeDef.Methods) { // Process parameters foreach (ParameterDefinition paramDef in methodDef.Parameters) { for (int i = 0; i < paramDef.CustomAttributes.Count; i++) { if (ProcessAny <IParameterWeaver>(paramDef.CustomAttributes[i], paramDef, methodDef) && cleanUp) { i--; } } Weave.TriggerScan(paramDef, methodDef); } for (int i = 0; i < methodDef.CustomAttributes.Count; i++) { if (ProcessAny <IMethodWeaver>(methodDef.CustomAttributes[i], methodDef) && cleanUp) { i--; } } Weave.TriggerScan(methodDef); } for (int i = 0; i < typeDef.CustomAttributes.Count; i++) { if (ProcessAny <ITypeWeaver>(typeDef.CustomAttributes[i], typeDef) && cleanUp) { i--; } } Weave.TriggerScan(typeDef); } // Process module foreach (IModuleWeaver weaver in ModuleWeavers) { ProcessModuleWeaver(weaver.GetType(), weaver, false); } Weave.TriggerScan(Module.Assembly); if (cleanUp) { // Remove attribute definition for (int i = 0; i < Module.Types.Count; i++) { if (Extends <WeaverAttribute>(Module.Types[i])) { Module.Types.RemoveAt(i--); } } // Remove reference to Insider, Mono.Cecil for (int i = 0; i < Module.AssemblyReferences.Count; i++) { AssemblyNameReference assembly = Module.AssemblyReferences[i]; if (assembly.Name.StartsWith(ASSEMBLY_NAME) || assembly.Name.StartsWith("Mono.Cecil")) { Module.AssemblyReferences.RemoveAt(i--); } else if (Assemblies.ContainsKey(assembly.Name)) { AssemblyDefinition def = Assemblies[assembly.Name].Item2; if (def.MainModule.AssemblyReferences.Any(x => x.Name.StartsWith(ASSEMBLY_NAME))) { Module.AssemblyReferences.RemoveAt(i--); } } } } }
protected override Assembly Load(AssemblyName args) { if (Assemblies.ContainsKey(args.Name)) { return(Assemblies[args.Name]); } var separatorIndex = args.Name.IndexOf(",", StringComparison.Ordinal); var assemblyName = separatorIndex > 0 ? args.Name.Substring(0, separatorIndex) : args.Name; var assembly = TryLoadExistingAssemblyName(args.FullName); if (assembly != null) { Assemblies[args.Name] = assembly; return(assembly); } // Try to load assembly using version. var version = args.Version; if (version != null) { var assemblyByVersion = TryLoadByVersion(AssemblyPaths, assemblyName, version.Major + "." + version.Minor + "." + version.Build + "."); if (assemblyByVersion != null) { Assemblies[args.Name] = assemblyByVersion; return(assemblyByVersion); } assemblyByVersion = TryLoadByVersion(AssemblyPaths, assemblyName, version.Major + "." + version.Minor + "."); if (assemblyByVersion != null) { Assemblies[args.Name] = assemblyByVersion; return(assemblyByVersion); } assemblyByVersion = TryLoadByVersion(AssemblyPaths, assemblyName, version.Major + "."); if (assemblyByVersion != null) { Assemblies[args.Name] = assemblyByVersion; return(assemblyByVersion); } } // Try to load assembly using full name, which includes version too. assembly = TryLoadByAssemblyName(args.FullName); if (assembly != null) { Assemblies[args.Name] = assembly; return(assembly); } // Try to load assembly using short assembly name. assembly = AssemblyLoadUtility.TryLoadByNameOrVersion(AssemblyPaths, assemblyName); if (assembly != null) { Assemblies[args.Name] = assembly; return(assembly); } Assemblies[args.Name] = TryLoadByAssemblyName(assemblyName); return(Assemblies[args.Name]); }