private static IEnumerable GetFilePaths()

in src/lib/Microsoft.Fx.Portability.Cci/HostEnvironment.cs [781:838]


        private static IEnumerable<string> GetFilePaths(IEnumerable<string> paths, Action<string> perResolvedPathAction, bool recursive = false)
        {
            foreach (var path in paths)
            {
                if (path == null)
                {
                    continue;
                }

                string resolvedPath = Environment.ExpandEnvironmentVariables(path);

                if (Directory.Exists(resolvedPath))
                {
                    perResolvedPathAction(resolvedPath);

                    for (int extIndex = 0; extIndex < ProbingExtensions.Length; extIndex++)
                    {
                        var searchPattern = "*" + ProbingExtensions[extIndex];
                        foreach (var file in Directory.EnumerateFiles(resolvedPath, searchPattern))
                        {
                            yield return file;
                        }
                    }

                    if (recursive)
                    {
                        // Recursively do the same for sub-folders
                        foreach (var file in GetFilePaths(Directory.EnumerateDirectories(resolvedPath), perResolvedPathAction, recursive))
                        {
                            yield return file;
                        }
                    }
                }
                else if (Path.GetFileName(resolvedPath).Contains('*'))
                {
                    IEnumerable<string> files;

                    // Cannot yield a value in the body of a try-catch with catch clause.
                    try
                    {
                        files = Directory.EnumerateFiles(Path.GetDirectoryName(resolvedPath), Path.GetFileName(resolvedPath));
                    }
                    catch (ArgumentException)
                    {
                        files = new[] { resolvedPath };
                    }

                    foreach (var file in files)
                    {
                        yield return file;
                    }
                }
                else
                {
                    yield return resolvedPath;
                }
            }
        }