Baseline.FileSet.getAllDistinctFiles C# (CSharp) Method

getAllDistinctFiles() private method

private getAllDistinctFiles ( string path, string pattern ) : IEnumerable
path string
pattern string
return IEnumerable
        private IEnumerable<string> getAllDistinctFiles(string path, string pattern)
        {
            if (pattern.IsEmpty()) return new string[0];

            return pattern.Split(';').SelectMany(x =>
            {
                var fullPath = path;
                var dirParts = x.Replace("\\", "/").Split('/');
                var filePattern = x;

                if (dirParts.Length > 1)
                {
                    var subFolder = dirParts.Take(dirParts.Length - 1).Join(Path.DirectorySeparatorChar.ToString());
                    fullPath = Path.Combine(fullPath, subFolder);
                    filePattern = dirParts.Last();
                }

                var directory = new DirectoryInfo(fullPath);
                var searchOption = DeepSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

                try
                {
                    return directory.Exists
                               ? Directory.GetFiles(fullPath, filePattern, searchOption)
                               : new string[0];
                }
                catch (DirectoryNotFoundException)
                {
                    return new string[0];
                }
            }).Distinct();
        }