private static void LoadInjection() { try { var directory = Path.GetDirectoryName(Environment.CurrentDirectory); var files = Directory.GetFiles(Environment.CurrentDirectory, "CInject.Injections.dll"); foreach (var assemblyName in files) { var assemblyInjectionCode = new ReflectionAssemblyResolver(assemblyName); List <Type> injectTypes = assemblyInjectionCode.FindTypes <ICInject>(); //ICInject 的实现类 foreach (var injectType in injectTypes) { _injectTypeDict.Add(injectType.Name, injectType); } //Startup foreach (Type t in assemblyInjectionCode.Assembly.GetTypes()) { if (t.Name.ToString() == "Startup") { _injectTypeDict.Add(t.Name.ToString(), t); } } } } catch (Exception ex) { throw ex; } }
private void AddInjectionAssembly(string assemblyName) { ReflectionAssemblyResolver assemblyInjectionCode = null; if (CacheStore.Exists <ReflectionAssemblyResolver>("injection|" + assemblyName)) { assemblyInjectionCode = CacheStore.Get <ReflectionAssemblyResolver>("injection|" + assemblyName); } else { assemblyInjectionCode = new ReflectionAssemblyResolver(assemblyName); CacheStore.Add <ReflectionAssemblyResolver>("injection|" + assemblyName, assemblyInjectionCode); } var nodeAssembly = new TreeNode { Text = Path.GetFileName(assemblyName), Tag = assemblyInjectionCode }; List <Type> types = assemblyInjectionCode.FindTypes <ICInject>(); for (int i = 0; i < types.Count; i++) { OnBindInjectors(assemblyInjectionCode, types[i], nodeAssembly, true); } // don't show the assembly if it does not have any injectors if (types.Count > 0) { _rootInjection.Nodes.Add(nodeAssembly); treeInjectionCode.ExpandAll(); } _injectorAssemblyLoaded = true; SendMessageToPlugins(EventType.InjectionAssemblyLoaded, null, null, assemblyName); }
private void AddInjectionAssembly(string assemblyName) { ReflectionAssemblyResolver assemblyInjectionCode = null; if (CacheStore.Exists<ReflectionAssemblyResolver>("injection|" + assemblyName)) { assemblyInjectionCode = CacheStore.Get<ReflectionAssemblyResolver>("injection|" + assemblyName); } else { assemblyInjectionCode = new ReflectionAssemblyResolver(assemblyName); CacheStore.Add<ReflectionAssemblyResolver>("injection|" + assemblyName, assemblyInjectionCode); } var nodeAssembly = new TreeNode { Text = Path.GetFileName(assemblyName), Tag = assemblyInjectionCode }; List<Type> types = assemblyInjectionCode.FindTypes<ICInject>(); for (int i = 0; i < types.Count; i++) { OnBindInjectors(assemblyInjectionCode, types[i], nodeAssembly, true); } // don't show the assembly if it does not have any injectors if (types.Count > 0) { _rootInjection.Nodes.Add(nodeAssembly); treeInjectionCode.ExpandAll(); } _injectorAssemblyLoaded = true; SendMessageToPlugins(EventType.InjectionAssemblyLoaded, null, null, assemblyName); }
private void LoadInject() { _mapping = new List <InjectionMapping>(); var directory = Path.GetDirectoryName(Application.ExecutablePath); Type type = null; MethodDefinition Method = null; MonoAssemblyResolver Assembly = null; if (directory != null) { var files = Directory.GetFiles(directory, "CInject.Injections.dll"); foreach (var assemblyName in files) { var assemblyInjectionCode = new ReflectionAssemblyResolver(assemblyName); //取值 type foreach (Type t in assemblyInjectionCode.Assembly.GetTypes()) { if (t.Name.ToString() == "Startup") { type = t; } ; } } var filess = Directory.GetFiles(directory, "CInject.SampleWinform.exe"); foreach (var assemblyName in files) { MonoAssemblyResolver assemblyTarget = new MonoAssemblyResolver(assemblyName); // add node var nodeAssembly = new TreeNode { Text = Path.GetFileName(assemblyName), Tag = new BindItem { Assembly = assemblyTarget, Method = null } }; _rootTarget.Nodes.Add(nodeAssembly); List <TypeDefinition> types = assemblyTarget.FindClasses(); for (int i = 0; i < types.Count; i++) { if (types[i].HasMethods) { if (types[i].Name == "Program") { var methodDefinitions = types[i].GetMethods(false); for (int j = 0; j < methodDefinitions.Count; j++) { if (methodDefinitions[i].Name == "Main") { Method = methodDefinitions[i]; Assembly = assemblyTarget; } } } } } } _mapping.Add(new InjectionMapping(Assembly, Method, type)); } }