/// <summary> /// Loads and returns all Drupal configuration files from the calling directory (<paramref name="directory"/>). /// </summary> /// <param name="directory">The directory.</param> /// <param name="nodeValid">Predicate function for determining which configuration nodes will be included in the /// loaded files (if <paramref name="nodeValid"/> returns <c>true</c>), and which will be ignored. Note that this /// function will be used <strong>only for root config nodes</strong> in all the files.</param> /// <param name="recursively">Determines if subdirectories of <paramref name="directory"/> should also be searched /// for config files or not.</param> /// <returns>Enumeration of <see cref="ConfigurationFile"/> instances, each representing one Drupal configuration /// file from <paramref name="directory"/>.</returns> internal static IEnumerable <ConfigurationFile> GetConfigurationFiles([NotNull] this DirectoryInfo directory, Predicate <IConfigNode> nodeValid = null, bool recursively = true) { IEnumerable <ConfigurationFile> localFiles = directory.GetFiles("*.yml").Select(f => ConfigurationFile.TryLoadFromFile(f, out ConfigurationFile configFile, nodeValid) ? configFile : null).Where(cf => cf != null); if (recursively) { localFiles = localFiles.Union(directory.GetDirectories() .Where(d => !ForbiddenDirectories.Contains(d.Name)) // ReSharper disable once RedundantArgumentDefaultValue .SelectMany(d => GetConfigurationFiles(d, nodeValid, true))); } return(localFiles); }