private static IEnumerable <string> GetAssemblyPathesForAllPlugins( string basePath, IEnumerable <string> whiteList = null) { // Return all the plugin folder names if white list is empty if (whiteList == null || whiteList.Count() == 0) { foreach (string pluginPath in Directory.GetDirectories(basePath)) { foreach (string assemblyPath in PluginAssembyLoader. GetAssemblyPathesForPlugin(pluginPath)) { yield return(assemblyPath); } } yield break; } List <PluginInfo> pluginInfos = new List <PluginInfo>(); // If white list is presend then return the names of plugin folders // while respecting the white list List <string> list = whiteList.Select(s => s).ToList(); foreach (string pluginPath in Directory.GetDirectories(basePath)) { string dirName = Path.GetFileName( pluginPath.RemoveTrailingSlash()); pluginInfos.Add(new PluginInfo { Name = dirName, BasePath = pluginPath }); string listItem = list.FirstOrDefault(s => s.Equals( dirName, StringComparison.InvariantCultureIgnoreCase)); if (!String.IsNullOrWhiteSpace(listItem)) { list.Remove(listItem); foreach (string assemblyPath in PluginAssembyLoader .GetAssemblyPathesForPlugin(pluginPath)) { yield return(assemblyPath); } } } PluginAssembyLoader.PluginInfos = pluginInfos.ToArray(); }
/// <summary> /// Get all the assembly (*.dll) pathes from the plugin directory /// including all subdirectories. /// </summary> /// <param name="pluginPath">Base path of the plugin directory.</param> /// <returns>A list of assembly pathes.</returns> private static IEnumerable <string> GetAssemblyPathesForPlugin( string pluginPath) { foreach (string assemblyPath in Directory.EnumerateFiles(pluginPath, "*.dll")) { yield return(assemblyPath); } foreach (string subDirPath in Directory.GetDirectories(pluginPath)) { foreach (var subAssemblyPath in PluginAssembyLoader .GetAssemblyPathesForPlugin(subDirPath)) { yield return(subAssemblyPath); } } }