private void SetDependencies() { foreach (var moduleInfo in _modules) { //Set dependencies according to assembly dependency foreach (var referencedAssemblyName in moduleInfo.Assembly.GetReferencedAssemblies()) { var referencedAssembly = Assembly.Load(referencedAssemblyName); var dependedModuleList = _modules.Where(m => m.Assembly == referencedAssembly).ToList(); if (dependedModuleList.Count > 0) { moduleInfo.Dependencies.AddRange(dependedModuleList); } } //Set dependencies for defined DependsOnAttribute attribute(s). foreach (var dependedModuleType in EddoModule.FindDependedModuleTypes(moduleInfo.Type)) { var dependedModuleInfo = _modules.FirstOrDefault(m => m.Type == dependedModuleType); if (dependedModuleInfo == null) { throw new Exception("没有发现 depended module " + dependedModuleType.AssemblyQualifiedName + " for " + moduleInfo.Type.AssemblyQualifiedName); } if ((moduleInfo.Dependencies.FirstOrDefault(dm => dm.Type == dependedModuleType) == null)) { moduleInfo.Dependencies.Add(dependedModuleInfo); } } } }
/// <summary> /// 查找依赖项模块 /// </summary> /// <param name="module"></param> /// <param name="allModules"></param> private static void FillDependedModules(Type module, ICollection <Type> allModules) { foreach (var dependedModule in EddoModule.FindDependedModuleTypes(module)) { if (!allModules.Contains(dependedModule)) { allModules.Add(dependedModule); FillDependedModules(dependedModule, allModules); } } }